Search code examples
bashshellwgetexit-code

wget gets not expecting exit code


I'm using wget into a bash script and I check the exit code to print some message. That's what I do:

wget -U mozilla -O my_page.html https://example.com/page
echo $?

Sometimes I get the page succesfully, because it exists, and somethimes I get a void file, because a 404 error (the page does not exist).

Well, I always get the exit code number 4, in every case.

The man page for wget says this for wget exit codes:

0   No problems occurred.
1   Generic error code.
2   Parse error---for instance, when parsing command-line options, the .wgetrc or .netrc...
3   File I/O error.
4   Network failure.
5   SSL verification failure.
6   Username/password authentication failure.
7   Protocol errors.
8   Server issued an error response.

I expect to get code 0 when I get a successful download and the code 8 when I get a 404 error.

What's happening?


Solution

  • I checked your command ( with small modification ) and for me it's work fine.

    wget -U mozilla -O test.html https://google.com/ >>/dev/null 2>&1; echo $?
    0  
    

    When try with non exist page

    wget -U mozilla -O test.html https://google.com/test >>/dev/null 2>&1; echo $?
    8
    

    Maybe there is something wrong indeed with the website which you trying to testing ?