Score:2

tail command retry flag not working with wildcards?

tr flag

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?

djdomi avatar
za flag
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)
iomv avatar
tr flag
@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
Score:4
it flag

/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).

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.