• Uncategorized

About linux : How-can-I-use-WGET-to-get-only-status-info-and-save-it-somewhere

Question Detail

can I use WGET to get, let’s say, status 200 OK and save that status somewhere? If not, how can I do that using ubuntu linux?


Question Answer

With curl you can

curl -L -o /dev/null -s -w "%{http_code}\n" http://google.com >> status.txt

You use --save-headers to add the headers to the output, put the output to the console using -O -, ignore the errors stream using >/dev/null and get only the status line using grep HTTP/.

You can then output that into a file using >status_file

$ wget --save-headers -O - http://google.com/ 2>/dev/null | grep HTTP/ > status_file

The question suggests that the output of the wget command be stored somewhere. As another alternative, the following example shows how to store the output of wget execution in a shell variable (wget_status). Where after the execution of the wget command the status of the execution is stored in the variable wget_status. The wget status is displayed in the console using the echo command.

$ wget_status=$(wget --server-response ${URL} 2>&1 | awk '/^  HTTP/{print $2}')
$ echo $wget_status

After the execution of the wget command, the execution status can be manipulated using the value of the wget_status variable.

For more information consult the following link as a reference:


The tests were executed using cloudshell on a linux system.

Linux cs-335831867014-default 5.10.90+ #1 SMP Wed Mar 23 09:10:07 UTC 2022 x86_64 GNU/Linux

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.