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

curl -Is | head -n 1 > out.txt
if grep -q “200” out.txt; then
echo site is working fine;
code=`cat out.txt`
echo “your site is down at ‘$TODAY’ with ‘$code’ error.” | mail -s “Your Website is down” -aFrom:Monitor\<\>
rm -rf out.txt


run the script manually

root@server:~/monitor/# 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

Leave a Reply

Your email address will not be published. Required fields are marked *