?
Solved

How to Tail a file that rolls over

Posted on 2002-05-31
3
Medium Priority
?
454 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 6

Accepted Solution

by:
bira earned 300 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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This tech tip describes how to install the Solaris Operating System from a tape backup that was created using the Solaris flash archive utility. I have used this procedure on the Solaris 8 and 9 OS, and it shoudl also work well on the Solaris 10 rel…
I promised to write further about my project, and here I am.  First, I needed to setup the Primary Server.  You can read how in this article: Setup FreeBSD Server with full HDD encryption (http://www.experts-exchange.com/OS/Unix/BSD/FreeBSD/A_3660-S…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
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.
Suggested Courses
Course of the Month14 days, 7 hours left to enroll

770 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