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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |