如何开始拖尾尚未创建的文件

Ame*_*ina 12 shell-script tail files

tail用来监视我知道将其进度写入磁盘的作业的进度。几乎总是,我知道他们在开始运行之前将创建哪个文件(作业由超级计算机上的调度程序调度)

tail在创建这些文件之前,有没有办法处理它们?我想这样做,同时避免竞争条件和/或对作业写入磁盘的方式或时间做出假设。

lar*_*sks 14

使用-F标志尾(假设你有tail来自 GNU coreutils):

tail -F file-that-does-not-exist
Run Code Online (Sandbox Code Playgroud)

来自man tail

   -F     same as --follow=name --retry
   --retry
          keep trying to open a file even when it is or becomes inaccessi?
          ble; useful when following by name, i.e., with --follow=name
   -f, --follow[={name|descriptor}]
          output appended data as the file grows; -f, --follow, and --fol?
          low=descriptor are equivalent
Run Code Online (Sandbox Code Playgroud)


ter*_*don 5

如果您的tail实现没有该--retry选项,您可能可以自己作弊并创建文件:

$ touch file && tail-f file
Run Code Online (Sandbox Code Playgroud)

根据您对所有权和权限的要求,这可能就足够了。