Created
July 1, 2021 05:03
-
-
Save svinther/9bc7e79afcffb09dee3027089d6ff772 to your computer and use it in GitHub Desktop.
pinglogger
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 | |
HOST=$1 | |
FAIL=0 | |
fail_hook() { | |
echo $(date) FAIL | |
} | |
unfail_hook() { | |
echo $(date) UNFAIL | |
} | |
while (true); do | |
PING=$(ping -c1 -W5 $HOST | grep icmp_seq) | |
RESULT=$? | |
[ -n "$PING" ] && echo $(date) $PING | |
if [ $RESULT -ne 0 -a $FAIL -eq 0 ]; then | |
FAIL=1 | |
fail_hook | |
elif [ $RESULT -eq 0 -a $FAIL -ne 0 ]; then | |
FAIL=0 | |
unfail_hook | |
fi | |
sleep 5 | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment