Monitor pinging multiple targets using the below script (sends 4 pings to each target, one after the other). read the comments for more details (how the output looks like etc.)
Make the script like this
cd ~ cat > ping-targets.sh # Copy paste the script # Press enter once, then CONTROL-C chmod +x ping-targets.sh
Make sure the script has these contents
#!/bin/bash # # How to run: ping-targets.sh <target1> <target2> ... # Example: ./ping-targets.sh 8.8.8.8 www.somesite1.com www.somesite2.com # # What this does: # Pings multiple targets, one after another (not simultaneously, 4 pings to each target) # # sample output of Example above: # [s1416349953_d2014-11-18_t17-32-33]: (8.8.8.8 y) (www.somesite1.com y) (www.somesite2.com n) # [s1416349972_d2014-11-18_t17-32-52]: (8.8.8.8 y) (www.somesite1.com y) (www.somesite2.com n) # # LEGEND: # y = yes (4 pings success) # n = no (0 ping success) # s = some (1,2 or 3 pings success) # # outputs to stdout, so redirect to save, or pipe to "tee filename" to save # (TARGETS="$@" while true; do DATENOW=$(date +s%s_d%Y-%m-%d_t%H-%M-%S) echo -n "[$DATENOW]: " for i in $TARGETS; do RESULT=`ping $i -c4` PACKETLOSS=`echo $RESULT | grep -o "[0-9]*% packet loss" | grep -o "[0-9]*"` if [ $PACKETLOSS -eq 0 ]; then STATUS="y" elif [ $PACKETLOSS -eq 100 ]; then STATUS="n" else STATUS="s" fi echo -n "($i $STATUS) " done echo done)
Run the script like this
ping-targets.sh 192.168.1.1 8.8.8.8 somesite1 somesite2
Or nohupped like so (output diverted to a different file other than nohup.out):
nohup ping-targets.sh 192.168.1.1 8.8.8.8 somesite1 somesite2 2>&1 > ~/ping-targets.out &
Example output:
[s1416349953_d2014-11-18_t17-32-33]: (8.8.8.8 y) (www.somesite1.com y) (www.somesite2.com n) [s1416349972_d2014-11-18_t17-32-52]: (8.8.8.8 y) (www.somesite1.com y) (www.somesite2.com n)
Notice that each line has the date, and the result of the ping. y for 100% succcess, n for 0 % success, and if you see an s that means 1,2 or 3 pings got thru.
The end.