in reply to •Re: Tailing rolling logs
in thread Tailing rolling logs

Hi, yup, looked at File::Tail, didn't think it could work with rolling logs, unless I read the spec wrong. Anyway, no matter I think I found a way to check this using the inode of the file and the File::Stat module, added these lines to the main loop:
if ( stat($file)->ino != $inode ) { # file has rolled if true close (FILE); open (FILE, "$file") or die "Cannot open file $file: $ +!\n"; $inode = stat(*FILE)->ino; }
Obviously set $inode before entering the loop. Does seem to do the trick, but I need to do some more testing Thanks Jon

Replies are listed 'Best First'.
•Re: Re: •Re: Tailing rolling logs
by merlyn (Sage) on Jan 30, 2004 at 13:43 UTC
    Hi, yup, looked at File::Tail, didn't think it could work with rolling logs, unless I read the spec wrong.
    Did you miss this part?
    If the file does not get altered for a while, "File::Tail" gets suspicious and startschecking if the file was trun- cated, or moved and recreated. If anything like that had happened, "File::Tail" will quietly reopen the file, and continue reading. The only way to affect what happens on reopen is by setting the reset_tail parameter (see below). The effect of this is that the scripts need not be aware when the logfiles were rotated, they will just quietly work on.

    -- Randal L. Schwartz, Perl hacker
    Be sure to read my standard disclaimer if this is a reply.