Skip to content

Instantly share code, notes, and snippets.

@invisiblek
Created September 26, 2015 15:38
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 invisiblek/5bdb0f492bc68b6d088f to your computer and use it in GitHub Desktop.
Save invisiblek/5bdb0f492bc68b6d088f to your computer and use it in GitHub Desktop.
#!/bin/bash
#
# Simple ping testing script
# By: Dan Pasanen
#
# Designed to be run as a cron job
#
# A space-separated list of hosts to monitor
hosts="rpi shrew invisiblek.org"
emailto="dan.pasanen+alert@gmail.com,3202662751@vtext.com"
emailfrom="pinger@mosquito.bandit.pug"
emailsubject="Pinger"
tmpfile="/tmp/pinger.tmp"
[ -f $tmpfile ] || touch $tmpfile
for host in $hosts; do
emailmsg=""
if ! fping $host > /dev/null; then
if ! grep -Fxq "$host" "$tmpfile"; then
emailmsg="$host went down!"
echo -ne "$host" >> "$tmpfile"
fi
else
if grep -Fxq "$host" "$tmpfile"; then
emailmsg="$host is back up!"
sed -i 's|'"$host"'||g' $tmpfile
fi
fi
[[ "$emailmsg" != "" ]] && sendemail -f "$emailfrom" -t "$emailto" -u "$emailsubject" -m "$emailmsg"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment