Re: script that runs all the time to monitor log file

2001-05-25 Thread Gary Stainburn

This sounds like a logrotate problem.

Do you have logrotate controlling this log file.

I may be wrong, but I think if you have the file open when logrotate 
kicks in, you filehandle will stay on the same file. i.e.

you open /var/log/maillog
logrotate removes /var/log/maillog.4
it then renames 3 to 4, 2 to 3, and 1 to 2.
it then renames /var/log/maillog to /var/log/maillog.1 and
then creates /var/log/maillog.

you will then be reading the end of /var/log/maillog.1 which will never 
get written to.

Gary
On Thursday 24 May 2001  7:28 pm, Chris Lott wrote:
> 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 = ) {
> if ($line =~ /blocked/) {
>system("echo '$line' | mail -s 'RBL rejection' foo\@bar.com");
> }
>  }
>  close(MAILLOG);
>  exit(1);

-- 
Gary Stainburn
 
This email does not contain private or confidential material as it
may be snooped on by interested government parties for unknown
and undisclosed purposes - Regulation of Investigatory Powers Act, 2000 




Re: script that runs all the time to monitor log file

2001-05-24 Thread Walt Mankowski

On Thu, May 24, 2001 at 02:37:18PM -0400, Craig Moynes/Markham/IBM wrote:
> 
> 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, hm.
> 
> 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 ?

There are several alternatives offered in perlfaq5 (search for 'How do
I do a "tail -f" in perl?'[1]).  Since the solutions there are variations 
on

loop forever
  reposition
  read to eof
  sleep a bit
end loop

they may (although I haven't tested it) get around the problems you
describe.

Walt

1.  Or, alternatively, "perldoc -q tail".

-- 
Walter C. Mankowski
Senior Software EngineerMyxa Corporation
phone: (610) 234-2626   fax: (610) 234-2640
email: [EMAIL PROTECTED]http://www.myxa.com




RE: script that runs all the time to monitor log file

2001-05-24 Thread Peter Cornelius

Is there another way I should be approaching this task?

How about not using tail?  I'm just ripping this off from the 'Perl
Cookbook' but:

for (;;) { #ever and ever 
while ()
# Do your thing
}

sleep $awhile;
seek(MAILLOG, 0, 1);
}
They claim that doing a seek will reset the EOF to the new position if there
is one.  They also have a solution using IO::Handle and its clearerr()
method.  Pretty much the same thing but add a use IO::Handle at the top and
change the seek to MAILLOG->clearerr();

Peter C.



Re: script that runs all the time to monitor log file

2001-05-24 Thread Craig Moynes/Markham/IBM


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

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 
   
   
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 = ) {
if ($line =~ /blocked/) {
   system("echo '$line' | mail -s 'RBL rejection' foo\@bar.com");
}
 }
 close(MAILLOG);
 exit(1);








script that runs all the time to monitor log file

2001-05-24 Thread Chris Lott

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 = ) {
if ($line =~ /blocked/) {
   system("echo '$line' | mail -s 'RBL rejection' foo\@bar.com");
}
 }
 close(MAILLOG);
 exit(1);