Last active
July 26, 2023 07:01
-
-
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.
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
#! /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