Created
September 12, 2013 03:31
-
-
Save victorreyesh/6532784 to your computer and use it in GitHub Desktop.
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
WEBSITE=mywebsite.com | |
SUBJECT_DOWN="$WEBSITE DOWN!" | |
SUBJECT_UP="$WEBSITE ONLINE" | |
EMAILID="an@example.com" | |
STRING=$(curl -A "myshell.co.uk - Website Monitoring Script" -s myshell.co.uk | grep -o "myshell.co.uk") | |
VALUE="myshell.co.uk" | |
LOCKFILE="/tmp/webcheck.lock" | |
if [ "$STRING" != "$VALUE" ] && [ ! -f "$LOCKFILE" ]; then | |
START_TIME=$(date +%s) | |
touch $LOCKFILE | |
echo "Website: $WEBSITE is down - $(date)" | mail -s "$SUBJECT_DOWN" $EMAILID | |
elif [ "$STRING" = "$VALUE" ] && [ -f "$LOCKFILE" ]; then | |
ELAPSED_TIME=$(($(date +%s) - START_TIME)) | |
rm -f $LOCKFILE | |
echo -e "Website: $WEBSITE is back online - $(date)\nDowntime: $ELAPSED_TIME seconds" | mail -s "$SUBJECT_UP" $EMAILID | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment