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.
-
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.
|