However, I only want to collect PASS entries if they have occured within the past 12 hours. I think this may involve a look ahead type regex but I can't wrap by thoughts around it. Can anyone offer suggestions?
Here's one thought I had was something like this:
#!/usr/bin/perl -w
use strict;
use Date::Manip;
my $now=ParseDate(scalar(localtime()));
my $hours_ago = DateCalc("12 hours ago",$now);
while (my $line=<DATA>){
chomp $line;
my ($timestamp,$metric,$serial,$source,$stuff,$foo,$status,$passfa
+il)
= split(/[\s\t\n]+/,$line);
next unless $passfail eq '*PASS*';
my $date = ParseDate($timestamp);
my $flag=Date_Cmp($hours_ago,$date);
if ( $flag < 0 ) {
printf "%s\n",$line;
}
}
exit(0);
__END__
2005-11-04/08:02:14.011 METRIC 00020036-0800093A log :Monitor: CALLER
+Status *PASS*
2005-11-04/08:11:30.924 METRIC 00020036-08000940 log :Monitor: CALLER
+Status *PASS*
2005-11-04/08:12:29.830 METRIC 00020036-08000941 log :Monitor: CALLER
+Status *PASS*
2005-11-04/09:12:28.790 METRIC 00020036-08000943 log :Monitor: CALLER
+Status *PASS*
2005-11-04/09:12:35.869 METRIC 00020036-08000944 log :Monitor: CALLER
+Status *PASS*
Obviously you'd have to tailor this to fit your needs, but
it is something you can work with...
Peter L. Berghold -- Unix Professional
Peter -at- Berghold -dot- Net; AOL IM redcowdawg Yahoo IM: blue_cowdawg
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.