Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I have a piece of software that rotates its log files when it restarts. However, during development, I am restarting it a lot, so I would like to monitor the latest log file at any time.

If I start less normally - less program.log - and hit Shift-f to tail, when the log file is rotated, I carry on monitoring the old log file. I assume this is because the inode number stays the same and less has an open file handle to that inode.

Is it possible to monitor the latest activity on whatever log file is currently called program.log?

Specifically, I am working on Sun OS, so a solution that works there would be ideal.

share|improve this question
    
maybe tail -F program.log | less will work –  sendmoreinfo May 1 '13 at 8:09
    
tail -f program.log have you tried this ? –  Rahul Patil May 1 '13 at 8:13

2 Answers 2

up vote 7 down vote accepted

Use less --follow-name if your version of less supports it. That option was introduced in version 416.

share|improve this answer
    
Excellent reply. Both Solaris 10 and Solaris 11 use less version 436 so this option is indeed available. –  unixhacker2010 Jul 30 '13 at 20:09

I just found the answer in this U&L Q&A titled: How to do a tail -f of log rotated files?.

Using tail:

(if installing GNU tail on your system is an option)

tail -F program.log

From the tail man page:

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

   -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

The key is the --retry switch. This tells the tail command to keep retrying to follow a file by name. The -F switch does both a -f and a --retry.

Using less

As @StephaneChazela pointed out in the comments the following will not work.

tail -F program.log | less

The only other option you have is to use less directly assuming it supports the --follow-name switch and less the file directly, forgoing using tail completely.

less --follow-name program.log
share|improve this answer
    
I strongly dislike Sun OS sometimes... –  Alex Chamberlain May 1 '13 at 8:39
    
I agree, I worked for years, it drives you nuts that the tooling is like 10 years old for some of the apps. Makes no sense. This site was invaluable for keeping your sanity on Solaris: sunfreeware.com/introduction.html –  slm May 1 '13 at 8:43
    
if you want more sanity, check out pkgsrc.org :) –  sendmoreinfo May 1 '13 at 9:06
    
That won't work nicely. Because less will hang if you do "G" pr "F". Which you can interrupt by doing "Ctrl-C", but then it kills tail. You can then immune tail to Ctrl-C, but it's still not very usable. –  Stéphane Chazelas May 1 '13 at 9:47
    
With regards to GNU tail: Check out this for information about what tools should be available on any Solaris host. (Actually GNU tail is there by default in Solaris 11). Solaris sysadmins often make it harder for their users because they leave the install at the very bare-bone install while GNU tools for Solaris are actually these days available directly from Oracle or in some cases part of default install. No reason not to make it part of your install. No reason to go to 'unofficial' repos. See link. –  unixhacker2010 Jul 30 '13 at 20:19

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.