Skip to content

Instantly share code, notes, and snippets.

@hlorand
Created September 23, 2017 22:32
Show Gist options
  • Save hlorand/96fea81f0311fab3db86fe7aefee6304 to your computer and use it in GitHub Desktop.
Save hlorand/96fea81f0311fab3db86fe7aefee6304 to your computer and use it in GitHub Desktop.
Website UP or DOWN checker
#!/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