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?
Perhaps this is the only answer, other than patching wget (a valid option):
wget -O somefile.html http://example.com/ || rm somefile.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With