1

I am using tail with option --follow=name to watch my log files in my servicemix instance (path = ${smx_home}/data/log/servicemix.log).

ServiceMix have a 'nice' feature to restart clean with servicemix clean that start fresh without cache and it seems it removes also the whole directory ${smx_home}/data.

When the folder and the log file are deleted, the message comes:

tail: data/log/servicemix.log: No such file or directory

and I have to press ctrl-C and restart my tail command like

tail --follow=name data/log/servicemix.log

The issue comes because the 'clean start' of ServiceMix remove the whole directory and not only the file and the initial inode is invalid.

Is there any way to make tail to reconnect to the deleted log?

If tail does not work, is there any other alternative (like e.g. with more or less)?

UPDATE:

I also tested multiple combination with -F --follow and --retry

tail --follow=name --retry data/log/servicemix.log

and this is not working too.

My tail version is

tail (GNU coreutils) 8.4
don_crissti
  • 82,805
рüффп
  • 1,707

3 Answers3

3

The version of tail in coreutils versions before 8.26 seem to have issues to continue a file which folder has been deleted. You can use less:

less --follow-name +F data/log/servicemix.log
Stephen Kitt
  • 434,908
pLumo
  • 22,565
1

You add the --retry option to --follow=name. Or use the shorthand for this combination -F. You will see an error that tail lost the file but it will find the new file in the new directory after creation.

Check your man page for the complete info.

Stephen Kitt
  • 434,908
Lucas
  • 2,845
  • 2
    Actually, the -F is short for '--follow-name. The -F (or --retry) is based on the fact that the directory is not removed, only the file is (re)moved and recreated. – Dirk Krijgsman Oct 16 '18 at 13:04
  • @Dirk -F is short for --follow=name --retry, not just --follow=name. – Stephen Kitt Oct 16 '18 at 13:22
  • @Stephan RoVo actually gave the right answer. It seems there is a bug that prevents the tail from working. I was able to reproduce this issue and -F didn't work for me. I still think this is not a duplicate question as the situation is different: not just the file but the directory is also removed. – Dirk Krijgsman Oct 17 '18 at 05:11
  • Whatever options I use, the tail never reconnects to the file. – рüффп Oct 17 '18 at 08:18
0

Note that for some particular version of tail, this is not possible due to a bug.

Once the directory is removed, the command tail will not be able to connect back to the file again. I was able to reproduce this before on an older setup but trying the answer above on my current version it works. So if the answer above doesn't work for you, check the version of tail.

Dirk Krijgsman
  • 549
  • 2
  • 6