Re: [Hampshire] tailing a file as/after it gets rotated?

Top Page

Reply to this message
Author: John Wesley
Date:  
To: Hampshire LUG Discussion List
Subject: Re: [Hampshire] tailing a file as/after it gets rotated?
2009/2/6 Victor Churchill <victorchurchill@???>

> Hi,
>
> I have a log file on a server, which I like to keep an eye on by
> running tail -f logfile (in fact I then pipe that through other stuff
> too). This sits in a dedicated screen session.
>
> Trouble is the file I am tailing gets moved by a cron job at 06:00
> every day and replaced by a new empty one. My tail job keeps watching
> the old log file even though it has now been renamed by the rotate
> procedure, and the new logfile is untailed.
>
> I am sure this is not a new thing but a (not so) quick google did not
> come up with a way round this. All I can think of is to have the cron
> job that rotates the log file send a HUP signal to any process tailing
> it, but I'm not sure how one would go about that or if that would
> actually work. (Having just experimented, I suspect not.)
> ( I have just noticed that this paragraph includes five occurrences of
> the word 'not', and that's not including these two. ;-)
>
> SO, does anybody know of a way to keep a tail on-target when the files
> get whiked away and replaced?
>
> --
> Please post to: Hampshire@???
> Web Interface: https://mailman.lug.org.uk/mailman/listinfo/hampshire
> LUG URL: http://www.hantslug.org.uk
> --------------------------------------------------------------
>


Try:

tail -F filetotail

This should tail to find and follow the new file when it appears.

jonh