Skip to content

Instantly share code, notes, and snippets.

@Jachimo
Last active September 7, 2017 18:06
Show Gist options
  • Save Jachimo/d067f8563131a5d83c46dda2ed80afc6 to your computer and use it in GitHub Desktop.
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.
#!/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