I'm writing a script that involves downloading and manipulating a file, and I want to ensure that the file is not incomplete (due to e.g. a dropped connection) before I work on it.
The most common way to verify the integrity of downloaded files is to use MD5 checksums. This assumes that the site you are downloading from actually published MD5 checksums of their files. You can verify a MD5 checksum by creating your own checksum of the downloaded file and comparing it to the published checksum. If they are identical the file you have downloaded is complete and not tampered with.
If you don't expect the file you are downloading to change you can precompute a checksum and hard code it into the script, but if the file is ever updated the verification will fail.
To create a MD5 checksum of a file run
This will create a checksum of "myFile" while downloading and save it to the file MD5SUM, possibly saving you some time.
In the case of a dropped connection I think the best way would be to check the exit codes of wget. If the download is successful without any errors wget will return
The return code of the command used to download the file will tell you if the command executed successfully or not. Typically, a return code of 0 denotes success and any non-zero number denotes an error. You can access the return code through the
A basic example using