Hi Monks,

I'm hoping someone can assist with the following problem. I have a log file that has output written to it all day. I need to check it for a specific error: "OutOfMemory". Once the word "OutOfMemory" is found, I email the line to the necessary parties and then resume looking for the error again. The caveat is that I need to resume checking the log file starting from the line after the last error found. This way I will only page out on new errors found. This is the part i'm struggling with

Below is a code snippet..i only need help with the requirement of how to resume looking for the next error in a file. Any help is greatly appreciated

sub resetFilePos { my $fileno = shift; my $mtime_curr = (stat($fileno))[9]; my $mtime_new = (stat($file_name))[9]; if ($mtime_curr + 5 <= $mtime_new) { close($fileno); open($fileno, "<",$file_name ) or die "Can't open file + $file_name"; } else { seek($fileno,0,1); } return $fileno; } sub process { my $file = "/$ENV{HOME}/Error.log"; eval { open ($tail,"<",$file_name) or die "Can't open file $f +ile_name"; for(;;) { for $line (<$tail>) { if ( /OutOfMemoryError/) { send_mail($_,$.); } } $tail = resetFilePos($tail); } close($tail); } } process();

In reply to Find error message starting at line after last error by dirtdog

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.