Created
May 24, 2012 23:47
-
-
Save alghanmi/2784927 to your computer and use it in GitHub Desktop.
HTTP Status Check - Report any non-200 response to given email address
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/sh | |
WEB_PAGE=$1 | |
ADMIN_EMAIL=$2 | |
EMAIL_SIGNATURE="Sent by $USER@$(hostname) on $(date)" | |
# Get HTTP server response code | |
result=$(curl -s -I $WEB_PAGE | grep HTTP/1.1 | awk {'print $2'}) | |
# Report a non-responsive server | |
if [ ! -n "$result" ] | |
then | |
echo -e "The server for the following web page is not responding:\n\t$WEB_PAGE\n\n$EMAIL_SIGNATURE" | mail -s "[URGENT] Server Not Responding" $ADMIN_EMAIL | |
exit 1 | |
fi | |
# Report a non-200 (i.e. HTTP OK) response | |
if [ $result -ne 200 ] | |
then | |
service tomcat restart | |
echo -e "The following webpage produced a(n) HTTP $result error:\n\t$WEB_PAGE\nTomcat was restarted\n\n$EMAIL_SIGNATURE" | mail -s "HTTP Error $result on $(hostname)" $ADMIN_EMAIL | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
HTTP Status Check
Bash script to check the availability of a website or a specific web page via HTTP response codes. A success is measured by getting an
HTTP 200 OK
.Usage Instructions
After downloading the script, make sure to make it executable:
To run the script from the command line, you need to specify the webpage/website you are checking and the email to report errors to:
Notes & Future Improvements