Skip to content

Instantly share code, notes, and snippets.

@svinther
Created July 1, 2021 05:03
Show Gist options
  • Save svinther/9bc7e79afcffb09dee3027089d6ff772 to your computer and use it in GitHub Desktop.
Save svinther/9bc7e79afcffb09dee3027089d6ff772 to your computer and use it in GitHub Desktop.
pinglogger
#!/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