大网数据广告活动
服务器运维问答

tail command retry flag not working with wildcards?

· 52CE 我爱测

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 s…

问题原文

原帖链接 · iomv · CC BY-SA 4.0

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?

已采纳解答

原帖链接 · parkamark · CC BY-SA 4.0

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

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2021-08-05)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。