1832834 Members
2846 Online
110047 Solutions
New Discussion

Behaviour of "tail -f"

 
Ian Cattrell
Occasional Contributor

Behaviour of "tail -f"

Hi

If a "tail -f" is running on a file and the file is renamed using mv, what will happen to the tail process? Will the process remain on the system indefinitely or will it eventually be killed?

Any help would be much appreciated.
4 REPLIES 4
John Palmer
Honored Contributor

Re: Behaviour of "tail -f"

Hi,

Tail will continue to read the 'moved' file and will remain forever until killed. The man pages mention an endless loop.

Regards,
John
Rick Garland
Honored Contributor

Re: Behaviour of "tail -f"

You'll be watching the 'mv'ed file.
Victor BERRIDGE
Honored Contributor

Re: Behaviour of "tail -f"

Exactly, as John and Rick have said:
Youd be watching an endless loop that would be the moved file.
Demo:
First window:
alphard:..adm/syslog>cat syslog.log >>titi
alphard:..adm/syslog>mv titi tutu
alphard:..adm/syslog>ll
total 2812
-rw-r--r-- 1 root root 10729 Oct 13 20:29 OLDsyslog.log
-r--r--r-- 1 root root 1307538 Oct 15 15:37 mail.log
-rw-r--r-- 1 root root 14729 Oct 17 11:33 syslog.log
-rw-rw-rw- 1 root sys 17346 Oct 17 19:07 tutu
alphard:..adm/syslog>date >> tutu
alphard:..adm/syslog>date >> tutu
alphard:..adm/syslog>date >> tutu
alphard:..adm/syslog>

2nd window:
119537667 -a
Oct 16 09:14:52 alphard ftpd[2603]: FTP LOGIN FROM 160.53.92.88 [160.53.92.88], patrol
Oct 16 09:35:06 alphard ftpd[2603]: exiting on signal 14
Oct 16 18:57:29 alphard : su : + ttyp4 vbe-logadm
Oct 16 19:11:51 alphard : su : + ta oracle-root
Oct 16 19:18:16 alphard : su : + ta oracle-dbatrd2
Oct 16 19:26:49 alphard : su : + ta oracle-root
Oct 17 11:33:41 alphard bootpd[28558]: bootpd 2.4 #1.17.112.7: Wed Apr 14 05:09:15 GMT 1999
Oct 17 11:33:42 alphard bootpd[28558]: reading "/etc/bootptab"
Oct 17 11:33:42 alphard bootpd[28558]: read 2 entries from "/etc/bootptab"
Tue Oct 17 19:07:52 METDST 2000
Tue Oct 17 19:07:58 METDST 2000
Tue Oct 17 19:08:01 METDST 2000
MARREEL Chris_1
Regular Advisor

Re: Behaviour of "tail -f"

The above mentioned answers are ONLY true if the source and destination of the move-command is on the SAME logical volume !

If you move the file to another logical volume the inode changes and from that moment on you won't see any new additions with tail !
So if you move on the SAME logical volume you will see new additions to the file because the inode-number hasn't changed, but if you move to another logical volume the inode-number changes and then you have to kill the 'tail -f' and issue a new 'tail -f' of the new file.

Hope this explains a little bit more,