tags:

views:

907

answers:

1

I have been trying to figure out a way to make wget only create a file if the actual download response is valid, meaning no 404 or 500 status code, only 200.

However, when using the -O option (to specify filename) it will always create the file, with the content of the error page, and I haven't found a way to specify that it should ignore it if it recieves a 404 response-header.

Do I need to check the exit-code and pipe the output or is there a better alternative?

+2  A: 

Perhaps this is the only answer, other than patching wget (a valid option):

wget -O somefile.html http://example.com/ || rm somefile.html
MattJ
Good enough, works for me. Thanks a bunch!
jishi