0

I have written a unix script using curl that returns the response headers of the http url.However i would like to do the same for https and i am unable to do so.I need these to check if the sites are up and running or not.

My code for http sites

status=$(curl -s --head  -w %{http_code} http://10.196.56.112:9081/ -o /dev/null)
echo $status

if [ "$status" == "000" ];
then echo "Server down"

else
echo "Server up"
fi

1 Answer 1

1

It works exactly the same way for HTTPS.

The only little difference is that HTTPS implies that curl will verify the TLS certificate of the server and unless you use --insecure curl will exit with an error if it can't verify it successfully. In your example here, you use an IP address and not a name and that will most certainly cause a certificate check to fail.

Sign up to request clarification or add additional context in comments.

7 Comments

Thanks Daniel.. It did work !!! Cheers. However could you help me in depth regarding why curl will exit with an error?
If you have another question, file another question!
I have a dynamic DNS configured at my end so will it skip the certificate check when the final address is resolved?
curl only skips the check if you use -k / --insecure
Is there a way to set a time limit that the curl waits for the header response?As i do not want my entire script to wait for a long time just because a single URL is in hung state.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.