in reply to Find error message starting at line after last error
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.
|
---|