This is a problem with tail that I have run into as well.
If the file size gets reset the stored location of EOF remains the same
which is a problem. As the file is written too the size is still below that
of what tail is looking at. You can add a stat check to watch filesize and
reset the counter when the size is smaller than the previous one.
I think there was another issue with using tail, hmmmmm.
You can test it out on the command line though to ensure I have my brain in
alignment.
Ohh the other problem ...
Your script will wait for more data from tail, and if the file size is
reset it just sits there. To solve this I created a controller process
that spawns off the log reader and then the controller monitors the logfile
size, if it drops below the last size it kills off the log reader process
and respawns it.
Any other solutions perl gods ?
-----------------------------------------
Craig Moynes
Internship Student
netCC Development
IBM Global Services, Canada
Tel: (905) 316-3486
[EMAIL PROTECTED]
Chris Lott
<chrisl@thethirds To: "'[EMAIL PROTECTED]'"
<[EMAIL PROTECTED]>
ector.com> cc:
Subject: script that runs all the time
to monitor log file
05/24/01 02:28 PM
I have a simple little perl program that monitors the email log file for
rejected messages (see below). I start the program using "nohup script.pl
&"
and it works fine, sending me an email with info about each rejected
message. However, it just dies out randomly after a day or so for no reason
that I can figure. The script is still there as a process, but it doesn't
perform.
Is there another way I should be approaching this task?
#!/usr/bin/perl
$maillog = "/var/log/maillog";
$TAIL = "/usr/bin/tail";
open(MAILLOG,"$TAIL -f $maillog |") || die("Can't $TAIL -f
$maillog");
while($line = <MAILLOG>) {
if ($line =~ /blocked/) {
system("echo '$line' | mail -s 'RBL rejection' foo\@bar.com");
}
}
close(MAILLOG);
exit(1);