Category: Website Monitoring

Simple website monitoring script

Install Curl

Ubuntu or other debian distributions

apt-get install curl

Centos or other Redhat based distributions 

yum install curl

Create a file and add below script to the file

TODAY=$(date)
curl -Is https://gkitsystems.com/ | head -n 1 > out.txt
if grep -q “200” out.txt; then
echo site is working fine;
else
code=`cat out.txt`
echo “your site http://gkitsystems.com/ is down at ‘$TODAY’ with ‘$code’ error.” | mail -s “Your Website gkitsystems.com is down” -aFrom:Monitor\<monitor@yourserver.com\> yourmail@domain.com
rm -rf out.txt
fi

Output

run the script manually

root@server:~/monitor/# sh monitoring.sh
site is working fine

Now we are going to make the website throw 403 error and test the script

edit apache configuration file and add below lines in between <Directory> </Directory> for the website

Order deny,allow
Deny from all

Restart apache after editing, you should get 403 error 

Lets run the script again manually

you should have a notification email in inbox now

revert back the apache configuration to get your site functioning

Note : Edit URL subject and mail id as required

Feel free to comment if you have any issues with the script