Check wget return code

hello
check this script it jump to else part, in n both cases,
(if files exist or not)

wget $MIRROR/kkk.zip && wget $MIRROR/jjj.zip
RC="$?"
if [[ "$RC" -ne 1 ]]
then
echo -e "$RED Ooops, Download links are broken...! $RESET"
else
echo -e "$GREEN Everything is fine, Cheers ... $RESET"
fi

What are you expecting?
What do you mean by both cases?

This is true whenever "$RC" is not 1 ("ne" = "not equal").

You probably mean:

if [ $RC -eq 0 ] ; then
     echo "success"
else
     echo "failed"
fi

because a return code of "0" usually means success, everything else means some error condition.

I hope this helps.

bakunin

@bakunin

You just reversed the terms but OP condition logic is still the same, unless that it gets something else than a 0 or 1.

why not just wget http://url1 http://url2 instead of running wget twice?

Also, if the page redirects to an error page instead of giving a proper 404, wget will not detect an error.

1 Like