Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Only create file if http status 200 with wget?

Tags:

wget

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?

like image 333
jishi Avatar asked Mar 16 '09 08:03

jishi


1 Answers

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

wget -O somefile.html http://example.com/ || rm somefile.html
like image 169
MattJ Avatar answered Sep 26 '22 09:09

MattJ