LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   tail file if the name is changeable (https://www.linuxquestions.org/questions/linux-newbie-8/tail-file-if-the-name-is-changeable-779211/)

m1n 01-01-2010 05:05 AM

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!

EricTRA 01-01-2010 05:26 AM

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

GooseYArd 01-01-2010 05:53 AM

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.

syg00 01-01-2010 06:10 AM

If tail can do that, I have to ask why it doesn't use inotify rather than a (tight) loop to check the file.

GooseYArd 01-01-2010 06:33 AM

I think its just because inotify is so new (at least compared to the gnu utils packages :) )

EricTRA 01-01-2010 06:35 AM

Quote:

Originally Posted by GooseYArd (Post 3810682)
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

GooseYArd 01-01-2010 06:48 AM

oh duh- I had no idea big F did that, you saved me some future typing erictra!

EricTRA 01-01-2010 07:09 AM

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


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