If you need to do anything other than display the results once you've isolated the uptime, you'll probably want a more useful value, such as seconds of uptime. Here's a script that will take an uptime statement and tell you the uptime in seconds. As with Stajich's solution, this may only work on uptimes of less than one year.

#! /usr/bin/perl use strict ; use warnings ; use Parse::RecDescent ; my $rules = q{ startrule: current_time 'up' uptime remainder eol { $return = $item[3] ; } current_time: /\d+:\d+[AP]M/ uptime: days(?) time { $return = (@{$item[1]})[0] + $item[2] ; } days: number_days 'days,' { $return = $item[1] * 86_400 ; } number_days: /\d+/ time: hours ':' minutes { $return = $item[1] + $item[3] ; } hours: /\d+/ { $return = $item[1] * 3_600 ; } minutes: /\d+/ { $return = $item[1] * 60 ; } remainder: /.+/ eol: /^\Z/ } ; my $parser = new Parse::RecDescent( $rules ) ; my @tests = ( '11:22PM up 4:30, 2 users, load averages: 0.25, 0.42, 0.40', '6:37PM up 4 days, 2:05, 2 users, load averages: 1.99, 1.65, 1.47' ) ; foreach my $test ( @tests ) { print $test . ': ' . $parser->startrule( $test ) . "\n"; }
Have fun!
_______________
D a m n D i r t y A p e
Home Node | Email

In reply to Re: pattern matching by DamnDirtyApe
in thread pattern matching by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.