Solved

How to Tail a file that rolls over

Posted on 2002-05-31
3
453 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 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

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

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

Attention: This article will no longer be maintained. If you have any questions, please feel free to mail me. jgh@FreeBSD.org Please see http://www.freebsd.org/doc/en_US.ISO8859-1/articles/freebsd-update-server/ for the updated article. It is avail…
Why Shell Scripting? Shell scripting is a powerful method of accessing UNIX systems and it is very flexible. Shell scripts are required when we want to execute a sequence of commands in Unix flavored operating systems. “Shell” is the command line i…
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
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.

726 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