Linux.com

check error code

Posted by: Anonymous Coward on January 13, 2007 04:37 AM
If you are going to use a script like this to head the top of a file list, wget the url, and then use sed -i to remove the first line, you should check the bash error code before you remove the url from the list:


  url=`head -n1<nobr> <wbr></nobr>.wget-list`

      wget -c $url
ERRORCODE=$?
if [ $ERRORCODE -eq 0 ]; then

      sed -si 1d<nobr> <wbr></nobr>.wget-list
else

      echo "ERROR: could not get $url" 1>&2

      exit $ERRORCODE
fi

Otherwise, if wget fails, (not uncommon if server temporarily overloaded or down, etc) you remove the url you wanted to download from your DL list but you don't get your file.

#

Return to Make Wget cater to your needs