With Bash scripting you can monitor the Availability of a Website in your environment.
In order to achieve this without any third party monitoring tool you can simply create a script which can check the URL status code and if that changes it can simply send an email to you with the latest status code in the email body after which you can troubleshoot the same.
For checking the URL periodically over a specified period of time you need to enter the script in the crontab entry with period like every 5 minutes or as per your need.
The below script will send you a mail whenever the www.xyz.com has any status other than 302
The below script will send you a mail whenever the www.xyz.com has any status other than 302
#!/bin/bash
status=`curl -I https://www.xyz.com 2>|/dev/null | grep HTTP/1.1 | awk '{print $2}'`
if [ $status = 200 ]
then echo "The domain is working fine " else echo "The domain is having some problem, last status was $status" | mail -s "Error on the Domain" [email protected]
fi
0 comments:
Post a Comment