Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: Tailing rolling logs

by coec (Chaplain)
on Jan 30, 2004 at 10:16 UTC ( [id://325192]=note: print w/replies, xml ) Need Help??


in reply to Tailing rolling logs

Hmm, how does 'it stop working'?
Depending entirely on how the log rotation occurs, after the rotation you could be looking at the original file, it just has a .1 extension now.
RedHat's logrotate, for example and depending on the options supplied, may move/create. That is, it will move the existing file to a new location (and name) and create a new file of the original name. Now, your running script (which I've called logr.pl for ease of reference) doesn't refer to the log file by name but by inode. A good way to test this (under Linux) is to start your script:
logr.pl -f messages
and get the process ID of logr.pl. 'ls -l /proc/<PID>/fd' and look at the file handles that are in use by your process. Now manually rotate the file and repeat the 'ls' above. In my tests, the logr.pl still had the original file open.
Under other Unixes, 'lsof' or 'fuser' may provide similar info.
As to a fix, you could include signal handling in logr.pl to re-read the file (or simply restart) on receipt of SIGHUP, for example.

I hope that answers the question (correctly)

Replies are listed 'Best First'.
Re: Re: Tailing rolling logs
by Anonymous Monk on Jan 30, 2004 at 10:32 UTC
    Hi, Yup that is exactly what is happening, the file is being renamed to xyz.log.1, hence the issue. Your sugestion is valid but I'd prefer to have something that is intelligent enough to know that the filename has changed and then reopen the filehandler, as opposed to any outside help. Something along the lines of checking the name of the file that the inode refers to to verify that it is still the expected filename. Thanks for your suggestion Jon
      I have no experience with it, but how about trying file test operator
      -C
      which gives you
      'Age of file (at startup) in days since inode change.'
      I'm hoping for 'since inode change' ...

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://325192]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (8)
As of 2024-03-28 09:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found