here i am trying to check if wget -s returns HTTP/1.1 200 OK using shell script. i am using this wget command to get the http status from url
#!/bin/sh
#
URL="http://www.example.com"
wget -S $URL
if i get it returns HTTP/1.1 200 OK, then it should exit else run scr.sh script.
How can i do this?
Here I'm using exit code of silent wget command:
wget -q --spider $URL
if [ $? -ne 0 ] ; then
echo "do something"
fi
In case if response is an error it runs some command.
Using wget:
SHOULD_EXIT=$(wget --server-response --content-on-error=off ${URL} | awk -F':' '$1 ~ / Status$/ { print $2 ~ /200 OK/ }')
${SHOULD_EXIT} will be 1 for 200 OK and 0 otherwise.
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