[TriLUG] YAPQ (yet another perl question)..

Greg Brown gwbrown1 at gmail.com
Thu Jun 11 15:24:12 EDT 2009


so close:

15998976 bytes total (8083968 bytes free)
routername#Total bytes: 15998976
Free bytes:  8

so it's picking up the total bytes but on the free bytes it's only picking
up the last digit of the total free.

On Thu, Jun 11, 2009 at 3:11 PM, Tanner Lovelace <clubjuggler at gmail.com>wrote:

> On Thu, Jun 11, 2009 at 2:20 PM, Greg Brown<gwbrown1 at gmail.com> wrote:
>
> > 15998976 bytes total (358912 bytes free)
>
> So, you're looking for this line..
>
> >        my( $which, $why, $match, $before, $after ) =
> $ssh->expect(30,'#');
> >
>
> Using this line, right?
>
> Instead of collecting everything in $before, use the power of perl::Expect
> and regular expressions to do something like this:
>
> my $string = "Not found";
> $ssh->expect(30,
>             [ ".*bytes total.*bytes free.*" => sub {
>                 my $self = shift;
>                 $string = $self->match();
>                 exp_continue;
>               } ],
>             '#'
>             );
> $string =~ m/([0123456789]+) bytes total.*([0123456789]+) bytes free/;
> print "Total bytes: $1\n";
> print "Free bytes:  $2\n";
>
> My testing seems to suggest this will work much better than what
> you're trying to do.
>
> Cheers,
> Tanner
>
> --
> Tanner Lovelace
> http://wtl.wayfarer.org/
> (fieldless) In fess two roundels in pale, a billet fesswise and an
> increscent, all sable.
> --
> TriLUG mailing list        : http://www.trilug.org/mailman/listinfo/trilug
> TriLUG FAQ  : http://www.trilug.org/wiki/Frequently_Asked_Questions
>



More information about the TriLUG mailing list