Last active
September 7, 2017 18:06
-
-
Save Jachimo/d067f8563131a5d83c46dda2ed80afc6 to your computer and use it in GitHub Desktop.
Ugly but useful hack to repeatedly (at a broad interval, e.g. 10s or 30s) ping a server and log whether it replied. Does not use cron.
This file contains hidden or 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
#!/usr/bin/env bash | |
## Sends a ping to a server and writes a failure or success log message | |
## Logs results to syslog; find and filter in Console, search for "PINGTEST" | |
# Change this as needed, must be server that responds to pings | |
PINGDEST=192.168.1.1 | |
# Interval in seconds to send a ping (e.g. send every X seconds) | |
INTERVAL=10 | |
while :; do | |
ping -t 2 -c 1 $PINGDEST 2>&1 >/dev/null | |
if [ $? -eq 0 ]; then | |
logger -t "PINGTEST" Ping to $PINGDEST successful | |
else | |
logger -t "PINGTEST" FAIL at `date` - no ping from $PINGDEST | |
fi | |
sleep $INTERVAL | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment