insensate has asked for the wisdom of the Perl Monks concerning the following question:

Greetings. I'm looking for a one-liner that will allow me to tail a growing log file that is rotated based on size. For example, I'm interested in watching insensate.log, once that log file gets above 500K in size it is rotated to insensate.log1 and a fresh insensate.log is initiated. A simple tail -f will cease once the file is swapped. The one-liner requirement comes from a desire to use the command at-will in the context of my daily administrative tasks. Thanks in advance for your ideas.

Jason

Replies are listed 'Best First'.
Re: Tailing A Swapped File
by zengargoyle (Deacon) on Mar 31, 2002 at 02:12 UTC
    perl -MFile::Tail -e'$|++;$r=tie *F,"File::Tail",(name=>"/var/log/messages");while(<F>){print}'

    See File::Tail.

Re: Tailing A Swapped File
by japh (Friar) on Mar 31, 2002 at 06:29 UTC
    The pertinent snippet:

    If the file does not get altered for a while, File::Tail gets suspicious and startschecking if the file was truncated, or moved and recreated. If anything like that had happened, File::Tail will quietly reopen the file, and continue reading.... The effect of this is that the scripts need not be aware when the logfiles were rotated, they will just quietly work on.