Average ping time

From EggeWiki
Revision as of 19:44, 8 March 2009 by Egge (talk | contribs) (New page: This perl one-liner sends ten 100 byte packets to '''hostname''', and then displays the average. <geshi lang="perl"> /usr/sbin/ping -s hostname 100 10 | perl -ne \ 'BEGIN{ $sum = 0.0; $c...)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

This perl one-liner sends ten 100 byte packets to hostname, and then displays the average.

<geshi lang="perl"> /usr/sbin/ping -s hostname 100 10 | perl -ne \ 'BEGIN{ $sum = 0.0; $count = 0} if (/time[=]([0-9]+.[0-9]+) ms/) { $sum += $1; $count++;} END{ $avg = $sum/$count; print "$avg\n"} ' </geshi>

This works with Solaris 10's ping, which outputs data in this format:

$ /usr/sbin/ping -s hostname 100 10
PING hostname : 100 data bytes
108 bytes from hostname (192.168.0.1): icmp_seq=0. time=0.607 ms
108 bytes from hostname (192.168.0.1): icmp_seq=1. time=0.500 ms
108 bytes from hostname (192.168.0.1): icmp_seq=2. time=0.500 ms