in reply to MRTG script should be easy
On my system, this outputs:#!/usr/bin/perl my $host = 'dslreports.com'; my $ping_data = `ping -c4 $host`; my ($sent, $rev, $lost, $min, $max, $avg); if ( $ping_data =~ /(\d+) packets transmitted, (\d+) packets received, (\d+)%/ + ) { ($sent, $recv, $lost) = ($1, $2, $3); print "\$sent=$sent, \$recv=$recv, \$lost=$lost\n"; } if ( $ping_data =~ m{round-trip min/avg/max = ([0-9\.]+)/([0-9\.]+)/([0-9\.]+) +} ) { ($min, $avg, $max) = ($1, $2, $3); print "\$min=$min, \$avg=$avg, \$max=$max\n"; } ## do what you will with those variables now...
You should probably read this section of perlop pertaining to the m// operator.$sent=4, $recv=4, $lost=0 $min=47.0, $avg=47.6, $max=48.4
PS: I admit those long regexes could be broken up, simplified, /x'ed, etc, but hopefully you get the point! Update: no more wrapping within the <code>, at least under my settings.
blokhead
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: MRTG script should be easy
by Tanalis (Curate) on May 20, 2003 at 07:54 UTC |