Skip to content

Instantly share code, notes, and snippets.

@kevyworks
Forked from sweetmandm/uptimemonitor.sh
Created September 8, 2017 10:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kevyworks/c7739e0600a7d095fea4a0974ad3551c to your computer and use it in GitHub Desktop.
Save kevyworks/c7739e0600a7d095fea4a0974ad3551c to your computer and use it in GitHub Desktop.
Cron job to monitor websites and send an email if the website is down.
#! /bin/sh
# A script to monitor uptime of websites,
# and notify by email if a website is down.
SITES="ADD COMMA-SEPARATED WEBSITES HERE"
EMAILS="ADD COMMA-SEPARATED EMAILS HERE"
for SITE in $(echo $SITES | tr "," " "); do
if [ ! -z "${SITE}" ]; then
RESPONSE=$(curl -s --head $SITE)
if echo $RESPONSE | grep "200 OK" > /dev/null
then
echo "The HTTP Server on ${SITE} is up!"
else
MESSAGE="The HTTP server at ${SITE} has failed to respond."
for EMAIL in $(echo $EMAILS | tr "," " "); do
SUBJECT="${SITE} (http) Failed"
echo $MESSAGE | mail -s "$SUBJECT" $EMAIL
echo $SUBJECT
echo "Alert sent to $EMAIL"
done
fi
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment