2

I want to tail a bunch of unknown directories names containing a particular non-existant file, e.g.:

tail -F /tmp/*/app.log

However that does not work as intended with the wildcard: if I create a file with that path, tail won't start following unless I restart the command. On the other hand if I run:

tail -F /tmp/example/app.log

as soon as the file appears the command will output: tail: '/tmp/example/app.log' has appeared; following new file

I have tried the -f filename --retry combination instead of -F and the result is the same.

How can that be solved and are there any other ways to achieve the same goal?

iomv
  • 123
  • 4
  • Does this answer your question? [Continuously monitor logs with tail that are occasionally rotated](https://serverfault.com/questions/53699/continuously-monitor-logs-with-tail-that-are-occasionally-rotated) – djdomi Aug 05 '21 at 14:50
  • @djdomi No it doesn't, that question explains how to use the `-F` flag, which in fact I highlight myself in my question that I know the use of it but I believe it is not working as intended with wildcards – iomv Aug 05 '21 at 15:04

1 Answers1

4

/tmp/*/app.log will be expanded by the shell (BASH I presume). If there exist matches, then this will be expanded to those matches and then passed as arguments to tail

$ find /tmp/test -type f
/tmp/test/a/app.log                                                                                                                                                                                                                                
/tmp/test/b/app.log                  

$ echo /tmp/test/*/app.log                                                                                                                                                                                        
/tmp/test/a/app.log /tmp/test/b/app.log

So, in the above case, tail would be configured to follow specifically app.log in a and app.log in b. If, at the time it was started, app.log in b didn't exist, it would not be followed. If new directories or files are created, it will also not follow them.

In the case of no matches, the unexpanded string will be passed as an argument to tail

$ echo /tmp/test/*/app2.log                                                                                                                                                                                     
/tmp/test/*/app2.log               

So, it will attempt to follow the literal pathname/filename /tmp/test/*/app2.log, which will probably never exist (or if it does exist, it's been created in a very odd way because having * as a directory name is not something I would advise doing under normal circumstances).

parkamark
  • 1,118
  • 6
  • 11