3 # vi: set softtabstop=4 shiftwidth=4 tabstop=8 expandtab:
5 # Pings a list of hosts and saves the summary to the directory given in the
10 echo "usage: $0 outdir host1 [host2 [...]]" 1>&2
18 if [ -n "$outdir" ] && [ -n "$hosts" ]
27 echo "output directory $outdir does not exist" 1>&2
31 filestamp
="$(date +%Y-%m-%d)"
32 timestamp
="$(date +%H:%M:%S/%s)"
33 file="$outdir/pingmon.$filestamp"
37 echo -e "\t\t\tHOST\t\tloss%\trttavg" > "$file"
42 ping -q -c 50 -i0.5
"$h" |
tail -2 > "$outdir/pending.$h" &
51 p
="$outdir/pending.$h"
53 # 20 packets transmitted, 20 received, 0% packet loss, time 9500ms
54 # rtt min/avg/max/mdev = 0.132/0.143/0.157/0.013 ms
56 pktloss
=$
(grep "packet loss" "$p" |
sed -e 's,^.* \([0-9.]\+\)%.*$,\1,')
58 rttavg
=$
(grep rtt
"$p" |
59 sed -e 's,^.*\([0-9.]\+\)/\([0-9.]\+\)/\([0-9.]\+\)/\([0-9.]\+\).*$,\2,')
60 echo -e "$timestamp\t$h\t$pktloss\t$rttavg" >> "$file"