Skip to content

Instantly share code, notes, and snippets.

@egg82
Last active March 8, 2017 20:03
Show Gist options
  • Save egg82/5a09a58d444e04eba5e0acb5060928ce to your computer and use it in GitHub Desktop.
Save egg82/5a09a58d444e04eba5e0acb5060928ce to your computer and use it in GitHub Desktop.
#!/bin/bash
NOTIFYEMAIL="you@gmail.com"
check_ip() {
s=0
for i in {1..20}
do
r=$( hping3 -c 1 -S -p $2 $1 |& grep "packet loss" | cut -d " " -f 7 | rev | cut -c 2- | rev )
s=$((s+$r))
done
s=$((s/20))
if [ $s -gt 85 ]
then
echo "Server down! IP: $1 Loss: $s%"
echo "$s% packet loss" | mail -a "From: Watcher <watcher@yourdomain.com>" -s "Server Down: $1" $NOTIFYEMAIL
else
echo "Server up! IP: $1 Loss: $s%"
fi
}
check_ip 1.2.3.4 22
check_ip 10.20.30.40 22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment