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
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
get GNU version of tail, and use
tail --retry -f a.log
tail --retry -f a.log
#!/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.