Created
September 23, 2017 22:32
-
-
Save hlorand/96fea81f0311fab3db86fe7aefee6304 to your computer and use it in GitHub Desktop.
Website UP or DOWN checker
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# check every 10 seconds if a website is up or down | |
WEBSITE=$1 | |
while true; do | |
#curl downloads only HTTP header in silent mode | |
#head gets the first line | |
#grep searches for HTTP 200 OK status code and outputs the number of lines found | |
STATUSCODE=`curl -s --head $WEBSITE | head -n 1` | |
if [ `echo $STATUSCODE | grep 200 -c` == 1 ] | |
then | |
echo -n `date "+%Y-%m-%d %H:%M:%S"` | |
echo " UP" | |
else | |
echo -n `date "+%Y-%m-%d %H:%M:%S"` | |
echo " DOWN - ERROR $STATUSCODE" | |
fi | |
sleep 10; | |
done; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment