Skip to content

Instantly share code, notes, and snippets.

@simbalinux
Created June 25, 2018 16:25
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 simbalinux/db3d6297c5d221f0638e3a6ba6d21aa0 to your computer and use it in GitHub Desktop.
Save simbalinux/db3d6297c5d221f0638e3a6ba6d21aa0 to your computer and use it in GitHub Desktop.
check uptime of sites
#!/bin/bash
SITESFILE=sites.txt #list the sites you want to monitor in this file
#EMAILS="you@email.com,someoneelse@email.com" #list of email addresses to receive alerts (comma separated)
while read site; do
if [ ! -z "${site}" ]; then
CURL=$(curl -s --head $site)
if echo $CURL | grep "200 OK" > /dev/null
then
echo "The HTTP server on ${site} is up!"
else
MESSAGE="This is an alert that your site ${site} has failed to respond 200 OK."
echo "${MESSAGE}"
# 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 < $SITESFILE
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment