Last active
March 8, 2017 20:03
-
-
Save egg82/5a09a58d444e04eba5e0acb5060928ce 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 | |
NOTIFYEMAIL="[email protected]" | |
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 <[email protected]>" -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