LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 01-01-2010, 06:05 AM   #1
m1n
Member
 
Registered: Feb 2009
Posts: 33

Rep: Reputation: 15
tail file if the name is changeable


Hi all i am facing a problem with tailing a log file. Logs of application located in one folder:

applog_20100101_0200.log <--log until 2 am january 1
applog_20100101_0456.log <--log until 4:56 am
applog.log <-- current log

Application can change log when ever it wants to. I need to monitor this log, what i do:

tail -f applog.log

But when app changes log my tail just stops. How can i tail applog.log all the time with out stops?

Thanks in advance!
 
Old 01-01-2010, 06:26 AM   #2
EricTRA
LQ Guru
 
Registered: May 2009
Location: Gibraltar, Gibraltar
Distribution: Fedora 20 with Awesome WM
Posts: 6,805
Blog Entries: 1

Rep: Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295
Hi,

When you're tailing a file and that file gets renamed then it's normal that the tail fails. What you could do is write a script that restart the tail command when inactive for a certain amount of time.

Kind regards,

Eric
 
Old 01-01-2010, 06:53 AM   #3
GooseYArd
Member
 
Registered: Jul 2009
Location: Reston, VA
Distribution: Slackware, Ubuntu, RHEL
Posts: 183

Rep: Reputation: 46
from the manpage:

-f, --follow[={name|descriptor}]
output appended data as the file grows; -f, --follow, and --follow=descriptor are equivalent

--follow=name

will follow the file by name, so if the file is moved, closed, and reopened during rotation, you'll start seeing the new file.

Last edited by GooseYArd; 01-01-2010 at 06:55 AM.
 
Old 01-01-2010, 07:10 AM   #4
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 15,935

Rep: Reputation: 2209Reputation: 2209Reputation: 2209Reputation: 2209Reputation: 2209Reputation: 2209Reputation: 2209Reputation: 2209Reputation: 2209Reputation: 2209Reputation: 2209
If tail can do that, I have to ask why it doesn't use inotify rather than a (tight) loop to check the file.
 
Old 01-01-2010, 07:33 AM   #5
GooseYArd
Member
 
Registered: Jul 2009
Location: Reston, VA
Distribution: Slackware, Ubuntu, RHEL
Posts: 183

Rep: Reputation: 46
I think its just because inotify is so new (at least compared to the gnu utils packages )
 
Old 01-01-2010, 07:35 AM   #6
EricTRA
LQ Guru
 
Registered: May 2009
Location: Gibraltar, Gibraltar
Distribution: Fedora 20 with Awesome WM
Posts: 6,805
Blog Entries: 1

Rep: Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295
Quote:
Originally Posted by GooseYArd View Post
from the manpage:

-f, --follow[={name|descriptor}]
output appended data as the file grows; -f, --follow, and --follow=descriptor are equivalent

--follow=name

will follow the file by name, so if the file is moved, closed, and reopened during rotation, you'll start seeing the new file.
If -f, --follow and --follow=descriptor are equivalent than what will --follow=name will do different?

Instead, also from the manpage
Code:
-F     same as --follow=name --retry
--retry
       keep trying to open a file even when it is or becomes inaccessible; useful when following by name, i.e., with --follow=name
Should be more useful.

Try
Code:
tail -F applog.log
and see if it does a better job.

Kind regards,

Eric
 
Old 01-01-2010, 07:48 AM   #7
GooseYArd
Member
 
Registered: Jul 2009
Location: Reston, VA
Distribution: Slackware, Ubuntu, RHEL
Posts: 183

Rep: Reputation: 46
oh duh- I had no idea big F did that, you saved me some future typing erictra!
 
Old 01-01-2010, 08:09 AM   #8
EricTRA
LQ Guru
 
Registered: May 2009
Location: Gibraltar, Gibraltar
Distribution: Fedora 20 with Awesome WM
Posts: 6,805
Blog Entries: 1

Rep: Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295
Hi,

No problem! You're welcome. Since you pointed out to the man page and I hardly use tail (only when troubleshooting something) I read through the man page myself and came across that one.

Kind regards,

Eric
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
tail file over tcp lloydie-t Linux - Networking 5 05-15-2007 03:18 AM
perl File::Tail hell whysyn Programming 2 03-14-2007 03:44 PM
I need to tail -f just a few colums o a text file ericcarlson Linux - General 3 01-30-2007 04:07 PM
DNS is changeable NAC Fedora 2 11-07-2006 05:09 AM
Tail Last Modified File in a Directory tyoungblood Linux - Software 3 08-12-2005 09:42 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 02:48 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration