Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I know if wget actually downloaded a file?

Tags:

shell

wget

I am writing a shell script that periodically downloads an archive off the internet and processes it.

I use wget -N $URL so that the file gets downloaded only if a newer version exists. How can I know if a file was actually downloaded so I can avoid unnecessary processing?

like image 207
Overnout Avatar asked Oct 24 '25 02:10

Overnout


1 Answers

You can try the following

FILE='filename'
CURRENT_TS=`stat -c %y $FILE`
wget -N $URL
NEW_TS=`stat -c %y $FILE`
if [ "$CURRENT_TS" != "$NEW_TS" ]; then
    # Do something here.
fi
like image 96
Doug Kress Avatar answered Oct 26 '25 22:10

Doug Kress



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!