linux poison RSS
linux poison Email

How to Watch Log Files in Realtime - Tailf

The most widely used command for monitoring log file is tail. Tail binary allows a user to watch the log file grow in realy time. Watching the log file grows can be done using an additional -f parameter. Alternatively, another approach to watch a log file grows can be done using tailf binary command.

Tailf:
tailf  will  print  out  the  last 10 lines of a file and then wait for the file to grow.  It is similar to tail -f but does not access the file when it is  not  grow-ing. This  has the side effect of not updating the access time for the file, so a filesystem flush does not occur periodically when no log activity is happening.

tailf is extremely useful for monitoring log files on  a  laptop  when  logging  is    infrequent  and  the  user desires that the hard disk spin down to conserve battery life.

Example: # tailf /var/log/squid/access.log

Similarly you can watch the same log file using -f argument

Example: # tail -f /var/log/squid/access.log


1 comments:

Jodie Cunningham said...

The only caveat is that tail -f is not suitable for long-term use, as logrotate will rotate the watched file to log.n+1. Since the read syscall is linked to the inode and not the filename, your app will never know the file was renamed and you will be waiting patiently for new data on a stale file.

You can use watch to periodically reiterate the tail command, or use something like xconsole to read a FIFO

Post a Comment

Related Posts with Thumbnails