Skip to content

Instantly share code, notes, and snippets.

@briantissue
Created September 20, 2018 18:57
Show Gist options
  • Save briantissue/7dd121c6443bc953d3cdbe6a06eb3d64 to your computer and use it in GitHub Desktop.
Save briantissue/7dd121c6443bc953d3cdbe6a06eb3d64 to your computer and use it in GitHub Desktop.
#!/bin/bash
# Program name: monitor-website.sh
# Written by Brian Tissue August 30th 2018
if [ "$(whoami)" != "root" ]; then
echo "Not running as root. Exiting..."
echo "Please use sudo -s then run this script again as root."
exit 0
else
echo "Running as root. Good"
fi
# URL You want to check ##############################################################
url="https://site-i-want-to-monitor.com"
# check url ##########################################################################
curl -fsSk -m 10 $url > /dev/null # This includes a webserver timeout of 10 seconds it'll alarm
if [ "$?" -eq 0 ]; # so if we have exit status of zero then webserver is RESPONDING
then
echo "Web server on $url is actively responding $(date)" >> /full-path/website-check-results.txt
exit 0
else
if [ "$?" -ne 0 ]; # so if we have exit status of anything but zero then the server is not RESPONDING
then
echo "Website is Currently Not Responding to Web Requests $(date)" | mutt -s "$url Currently Not Responding" -- emailaddress@emaildomain.com
fi
fi
# monitor-website.sh v2 ###############################################################
@briantissue
Copy link
Author

This code is pretty good, but it doesn't send an email update when the server comes back online.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment