Created
September 26, 2015 15:38
-
-
Save invisiblek/5bdb0f492bc68b6d088f to your computer and use it in GitHub Desktop.
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/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