Link to home
Start Free TrialLog in
Avatar of RudePuppyDog
RudePuppyDog

asked on

How to Tail a file that rolls over

I have a file "a.log" that when it gets to 1MB, renames to "a.log.1"  The new files is created to continue loggin called "a.log".

I want to send the out put of "a.log" to a log file on a nfs mounted directory in real time.  The "tail -f" command will work up until the file reaches 1MB and renames itself.  The "tail" command stops working at this point.

How can I get it to ouput the files contents after the 1MB limit is reached?

Thanx
ASKER CERTIFIED SOLUTION
Avatar of bira
bira

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of tekweni
tekweni

I dont have access to a unix box right now, but something like this may be worth putting into a script..

#!/bin/sh
while (1)
do
    tail -50 a.log.1 > /tmp/junkfile
    tail -50 a.log >> /tmp/junkfile
    cat /tmp/junkfile
    sleep 2
done

It almost certainly needs debugging, but the goal is to show you the last 50 entries regardless of the rollover between files.
get GNU version of tail, and use

  tail --retry -f a.log