What is the exit status of 'wget
' when it succeeds, and when it fails? Most likely, it reports the failure with a non-zero exit status, in which case it is largely trivial:
if wget http://example.com/remote/file ...
then mailx -s "File arrived at $(date)" [email protected] < /dev/null
else mailx -s "File did not arrive at $(date)" [email protected] < /dev/null
fi
If you must analyze the output from 'wget
' then you capture it and analyze it:
wget http://example.com/remote/file ... >wget.log 2>&1
x=$(tail -2 wget.log | sed 's/.*file.exe/file.exe/')
if [ "$x" = "file.exe' -- not retrieving." ]
then mailx -s "File did not arrive at $(date)" [email protected] < /dev/null
else mailx -s "File arrived at $(date)" [email protected] < /dev/null
fi
However, I worry in this case that there can be other errors that cause other messages which in turn lead to inaccurate mailing.