Tell me the best way to get a response from any url?
I have been asked to write a shell script To check if a URL is UP/Working or not for my Project.
I tried to find some suggestions on the internet but what i got is that i check whether the url exists or not
I first tried with wget
.
wget -S --spider https://genesis-dev.webbank.ssmb.com:21589/gop-ui/app.jsp 2>&1 | awk '/^ /'
if [ $? -ne 0 ]
then echo "Server is UP"
else
echo "Server is down"
fi
My next attempt was with curl
.
curl -ivs https://genesis-dev.webbank.ssmb.com:21589/opconsole-sit/opconsole.html#
if [ $? -ne 0 ]
then echo "Server is UP"
else
echo "Server is down"
fi
But, both are checking existence of the url not the response.
Best Answer
curl -Is http://www.yourURL.com | head -1
You can try this command to check any URL.Status code 200 OK
means that the request has succeeded and the URL is reachable.
You can also test URL availability and get the response code using telnet
command
telnet www.yourURL.com 80
80 is the port number.