Skip to content

Instantly share code, notes, and snippets.

@victorreyesh
Created September 12, 2013 03:31
Show Gist options
  • Save victorreyesh/6532784 to your computer and use it in GitHub Desktop.
Save victorreyesh/6532784 to your computer and use it in GitHub Desktop.
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