Solved

How to Tail a file that rolls over

Posted on 2002-05-31
3
447 Views
Last Modified: 2010-04-21
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
0
Comment
Question by:RudePuppyDog
3 Comments
 
LVL 6

Accepted Solution

by:
bira earned 100 total points
ID: 7047939
Hi
   Instead of "tail -f" , use a script like this:

    while true
    do
    tail -50 a.log
    done

  So, even when the a.log reaches 1MB and is renamed,
  it will go on showing the last 50 lines of the new one.
0
 
LVL 1

Expert Comment

by:tekweni
ID: 7048452
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.
0
 
LVL 51

Expert Comment

by:ahoffmann
ID: 7049818
get GNU version of tail, and use

  tail --retry -f a.log
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Hello fellow BSD lovers, I've created a patch process for patching openjdk6 for BSD (FreeBSD specifically), although I tried to keep all BSD versions in mind when creating my patch. Welcome to OpenJDK6 on BSD First let me start with a little …
FreeBSD on EC2 FreeBSD (https://www.freebsd.org) is a robust Unix-like operating system that has been around for many years. FreeBSD is available on Amazon EC2 through Amazon Machine Images (AMIs) provided by FreeBSD developer and security office…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
In a previous video, we went over how to export a DynamoDB table into Amazon S3.  In this video, we show how to load the export from S3 into a DynamoDB table.

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now