Created
August 7, 2013 08:44
-
-
Save drye/6172343 to your computer and use it in GitHub Desktop.
Continuously ping a set of hosts and log results to a file
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 | |
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