Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

dirtdog:

Like armstd mentioned, part of the problem is that you're rewinding the file to the beginning. I'd suggest tracking the last line of the file you examined each time with a log tailing module (as described to by i5513) or something like this (untested):

sub saveFilePos { my ($fileno, $filename) = @_; my $filepos = tell($fileno); open my $FH, '>', $filename or die "Can't open $fname: $!"; print $FH $filepos; close $FH; } sub process { my $file = "/$ENV{HOME}/Error.log"; my $file_last = "/$ENV{HOME}/Error.log.lastpos"; my $file_pos = 0; # Default to beginning of file eval { # Get last position in file (if any) open my $FH, '<', $file_last; if ($FH) { $file_pos = <$FH>; close $FH; } open ($tail,"<",$file_name) or die "Can't open file $file_name +"; seek($tail, $file_pos, 0); for(;;) { for $line (<$tail>) { if ( /OutOfMemoryError/) { send_mail($_,$.); } } } # Save last position examined saveFilePos($tail, $file_last); close($tail); } }

...roboticus

When your only tool is a hammer, all problems look like your thumb.


In reply to Re: Find error message starting at line after last error by roboticus
in thread 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":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (6)
As of 2024-04-25 08:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found