Skip to content

Instantly share code, notes, and snippets.

@sweetmandm
Last active July 26, 2023 07:01
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save sweetmandm/49567565fd72187ff76f to your computer and use it in GitHub Desktop.
Save sweetmandm/49567565fd72187ff76f 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