Don't use the Last-Modified header, that's dependent on the server. Anubhava@'s also works but this is less overhead and slightly more portable between Bourne shell variations:
This gets you what you need:
wget -N http://example.com/file.zip 2>&1 | grep "not retrieving" 2>&1 > /dev/null || unzip file.zip
- Get file
- Redirect stderr to stdout
- Check if "not retrieving" is in output (what wget prints when it's not downloading the file)
- If the "not retrieving" string does not exist in ouput, grep returns error code '1' and the file is unzipped. Otherwise, it just moves on silently.
It's essentially saying this, with more detail added for readability:
out=$(wget -N http://example.com/file.zip 2>&1) if [ $(echo $(out) | grep "not retrieving") ]; then echo "No new file; not unzipping" else unzip file.zip fi
curlandwgetcan be told not to download a file if it hasn't changed. See stackoverflow.com/q/32322456/258523 for a recent question and answer about this forwget.