Create a file only if the status is http 200 with wget?

I am trying to figure out a way to make wget only create a file if the valid response to the download is valid, i.e. a status code of 404 or 500, total 200.

However, when using the -O option (to specify the file name), it will always create a file with the contents of the error page, and I have not found a way to indicate that it should ignore it if it receives 404.

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

+8
wget
Mar 16 '09 at 8:41
source share
1 answer

Perhaps this is the only answer besides wget fix (valid option):

wget -O somefile.html http://example.com/ || rm somefile.html 
+13
Mar 16 '09 at 8:48
source



All Articles