>>>>> "JM" == Jeremy Muhlich <[EMAIL PROTECTED]> writes:

  JM> On Tue, 2006-02-21 at 11:38 -0800, Ranga Nathan wrote:
  >> I will have to re-start the script after every log rotation! I wish I 
  >> could do this programmatically. Perhaps another script to monitor the log 
  >> file and notice the sudden change in size or inode.

  JM> This is from the man page for tail:

  JM> --max-unchanged-stats=N
  JM>     with  --follow=name,  reopen  a FILE which has not changed size
  JM>     after N (default 5) iterations to see if it has  been  unlinked
  JM>     or renamed (this is the usual case of rotated log files)

  JM> So you could stat() the handle every so often (e.g. use a timeout on
  JM> your select() call) and store the size.  If the size doesn't change for
  JM> 5 iterations, stat the original filename to see if the mtime is
  JM> different from that of the handle.

  JM> Maybe you could watch the mtime instead of the size in the first place?
  JM> It's not clear to me why less watches for unchanging size and not mtime.
  JM> Perhaps some daemons somehow affect the mtime on their logs without
  JM> actually appending any data?

because of how inodes were created you can't watch mtime or size and
guarantee you have new data to read. one very bizarre corner case is
when the log file is overwritten with the exact same size of text as it
previously had. then the mtime has changed but you have no clue as to
where to read from as the size is the same. if the file was rotated then
you can see a new inode number and use that to start seeking from the
beginning. i don't think the unchanged counter thing is a good
idea as some log files may be dormant that long.

another issue is should you keep a handle open between tail polls or
open it fresh each time? since my code checks the inode number, opening
each time makes more sense.

tailing can't be done perfectly unless the filesystem provides some
hooks just for it such as a signal/callback that the file was
modified. and as i imply above, what file is the FS going to monitor
when rotation occurs? how would it know the name of the new log file
(which is up to the application)?

uri

-- 
Uri Guttman  ------  [EMAIL PROTECTED]  -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs  ----------------------------  http://jobs.perl.org
 
_______________________________________________
Boston-pm mailing list
[email protected]
http://mail.pm.org/mailman/listinfo/boston-pm

Reply via email to