Skip to content

Instantly share code, notes, and snippets.

@drye
Created August 7, 2013 08:44
Show Gist options
  • Save drye/6172343 to your computer and use it in GitHub Desktop.
Save drye/6172343 to your computer and use it in GitHub Desktop.
Continuously ping a set of hosts and log results to a file
#!/bin/bash
HOSTS="www.google.com www.bing.com"
# no of ping requests
COUNT=1
# timeout in seconds
TIMEOUT=1
LOG=/var/log/pingmonitor.log
while :
do
for myHost in $HOSTS
do
echo "Pinging $myHost"
ping -c $COUNT -W$TIMEOUT $myHost | grep received | while read pong; do printf "%s: %15s - %s\n" "$(date)" "$myHost" "$pong" >> $LOG; done
done
sleep 1
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment