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
2
  • 1
    The difference is that the directory is changed, this causes the answer to change also. Oct 16, 2018 at 13:06
  • @Dirk no, it doesn’t, -F works just fine on new directories. Oct 16, 2018 at 13:21

3 Answers 3

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
6
  • I updated my question with the version of tail. I am with 8.4 (gnu coreutil)
    – рüффп
    Oct 17, 2018 at 8:19
  • It looks a good alternative, but with that option it still misses the adding blank lines by pressing <enter>
    – рüффп
    Oct 17, 2018 at 10:28
  • @рüффп 8.4 would be the version in CentOS 6, and I tested this with less 436 on CentOS 6.9 and it works fine.
    – muru
    Oct 17, 2018 at 10:29
  • @muru I got the same "less" version on my CentOS 6.10 but adding blank line does not work by pressing enter, do you use another key?
    – рüффп
    Oct 17, 2018 at 10:33
  • 1
    I like tail because I can press enter to put artificial blanks between two writes in the log. I had similar issue like this in this post.
    – рüффп
    Oct 17, 2018 at 10:37
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.

4
  • 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. Oct 16, 2018 at 13:04
  • @Dirk -F is short for --follow=name --retry, not just --follow=name. Oct 16, 2018 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. Oct 17, 2018 at 5:11
  • Whatever options I use, the tail never reconnects to the file.
    – рüффп
    Oct 17, 2018 at 8: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.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .