in reply to Re: MRTG script should be easy
in thread MRTG script should be easy

Thank you all very much, for your kind assistance. I lost my camel book and, I guess, my brain with it. :-) Here is the output of my ping:
PING dslreports.com (209.123.109.175) from 10.0.1.1 : 56(84) bytes of +data. 64 bytes from www.dslreports.com (209.123.109.175): icmp_seq=0 ttl=51 +time=89.483 msec 64 bytes from www.dslreports.com (209.123.109.175): icmp_seq=1 ttl=51 +time=119.926 msec 64 bytes from www.dslreports.com (209.123.109.175): icmp_seq=2 ttl=51 +time=89.899 msec 64 bytes from www.dslreports.com (209.123.109.175): icmp_seq=3 ttl=51 +time=99.920 msec --- dslreports.com ping statistics --- 4 packets transmitted, 4 packets received, 0% packet loss round-trip min/avg/max/mdev = 89.483/99.807/119.926/12.344 ms
and here is the output of my script (obviously the numbers are not exactly the same since I did them one after the other):
0% packet loss round-trip min/avg/max/mdev = 89.908/91.193/95.024/2.221 ms 91 0 0
Having said that, I think I may look at the net:ping option in general and the graciously supplied script in particular. I briefly thought about NET:PING last night but this script was so close to working as it was, I hated to start from scratch and rewrite it. Especially if it turned out, I was just missing something small. Thank you all again, if any of you ever run for something...you have my vote :-) James

Replies are listed 'Best First'.
Re: Re: Re: MRTG script should be easy
by Skeeve (Parson) on May 21, 2003 at 08:18 UTC
    Okay. So here is how I would do it:
    use strict; my (%result); # Example lines searched for # 4 packets transmitted, 4 packets received, 0% packet loss # round-trip min/avg/max/mdev = 89.483/99.807/119.926/12.344 ms while (<DATA>) { SWITCH: { /transmitted/ && do { # This will "eat up" all "packets"-information $result{$2}=$1 while /(\d+)\s+packets\s+(\S+)/ +g; last SWITCH; }; /round-trip/ && do { # this will find all values seperated by / # and will store them under their key /(\S+)\s*=\s*(\S+)/; @result{split m(/),$1}= split m(/),$2; last SWITCH; }; } } # Your %result-keys depend on the output of ping print $result{'transmitted'}-$result{'received'}," packet(s) lost\n"; print $result{'avg'}," average\n"; print Dumper(\%result); __END__ PING dslreports.com (209.123.109.175) from 10.0.1.1 : 56(84) bytes of +data. 64 bytes from www.dslreports.com (209.123.109.175): icmp_seq=0 ttl=51 +time=89.483 msec 64 bytes from www.dslreports.com (209.123.109.175): icmp_seq=1 ttl=51 +time=119.926 msec 64 bytes from www.dslreports.com (209.123.109.175): icmp_seq=2 ttl=51 +time=89.899 msec 64 bytes from www.dslreports.com (209.123.109.175): icmp_seq=3 ttl=51 +time=99.920 msec --- dslreports.com ping statistics --- 4 packets transmitted, 4 packets received, 0% packet loss round-trip min/avg/max/mdev = 89.483/99.807/119.926/12.344 ms
    Example output:
    0 packet(s) lost 99.807 average $VAR1 = { 'received,' => '4', 'avg' => '99.807', 'min' => '89.483', 'mdev' => '12.344', 'max' => '119.926', 'transmitted,' => '4' };