Skip to content

Instantly share code, notes, and snippets.

@attebury
Created June 16, 2011 14:52
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save attebury/1029388 to your computer and use it in GitHub Desktop.
Save attebury/1029388 to your computer and use it in GitHub Desktop.
GeekTool website monitor
#!/bin/bash
# GeekTool script to display status of websites you monitor. See http://projects.tynsoe.org/en/geektool/
# Displays name of site if there's no error. Adds "!!!!" in front of unavailable site.
# Sends an email when a site is unavailable.
ARRAY=(
'awebsite.com'
'anotherwebsite.com'
'onemore.com'
)
ELEMENTS=${#ARRAY[@]}
function check {
STATUS=$?
case $STATUS in
6)
update "Unable to resolve host." $1
;;
7)
update "Failed to connect to host." $1
;;
18)
update "Partial file. Only a part of the file was transferred." $1
;;
77)
update "Problem with reading the SSL CA cert (path? access rights?)." $1
;;
78)
update "The resource referenced in the URL does not exist." $1
;;
0)
echo " " $1
;;
*)
echo " " $STATUS $1
;;
esac
}
function update {
# send error via email
echo $1 | mail -c address@email.com -s "Website Error: $2" another@email.com
# update GeekTool display
echo "!!!!" $2
}
for ((i=0;i<$ELEMENTS;i++)); do
curl -s -o "/dev/null" ${ARRAY[$i]}
check ${ARRAY[${i}]}
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment