This question already has an answer here:
This is along the lines of How to start tailing a file that has not been yet created with a twist: a file with the name already exists.
I have a program that is run multiple times; when the output file name is already in use, it renames the extant file by inserting
_XYZ before the file extension where
XYZ is the smallest integer (e.g.,
output_001.out already exists, etc.), and creates a new output file with the primary name.
If I tail the primary name, even with
-F, it begins tailing the extant file immediately and retains the handle to that inode even when the file is renamed, ignoring the new file.
The program is run on a shared cluster with queue management, so execution begins with long & variable lags.
Is it even possible to tail the new file without waiting for it to be created first? If so, how?