I am trying to write a script to test whether a website is available. I have got the curl trick from http://droptips.com/quick-command-to-check-the-status-of-a-url-linux-bsd-os-x an it returns HTTP/1.1 200 OK if it’s OK.
I now want to put that into an if … else block, and this is where it’s falling apart. When I try the following in Bash (no script yet):
test=`curl -Is https://internotes.net | head -n 1`; \
echo "$test"; \
echo "HTTP/1.1 200 OK"; \
if [ "$test" = "HTTP/1.1 200 OK" ]; \
then \
echo 'Good'; \
else \
echo 'Bad'; \
fi
It always returns something like:
HTTP/1.1 200 OK
HTTP/1.1 200 OK
Bad
The two strings look the same, but the comparison appears to fail.
What is the correct way to test this?
Aucun commentaire:
Enregistrer un commentaire