Reputation: 6757
I have a dir that saves a fresh log file for each run, so I use the following command to follow the latest log file:
tail -f $(ls -t | head -1)
So my question would be if there is any way to jump from one file to the next, if there is a newer log file available without having to stop the latest tail -f
and rerunning it?
Upvotes: 0
Views: 2621
Reputation: 718826
The -F
flag for tail
is supported in the GNU version. (It is in the GNU CoreUtils collection.)
Apparently, IBM have provide download for the GNU Toolkit for AIX, and apparently it includes a version of tail
that supports the -F
option.
You could use that in conjunction with the other answers to this question. (For example, using tail -F
with a symlink that you refresh regularly.)
Alternatively, if none of those solutions work for you, you could get hold of the GNU CoreUtils source code1, and modify the source for tail
to do what you want, and build it yourself on AIX.
1 - I haven't checked, but I expect that the IBM devs will be contributing back any changes they make to CoreUtils to get it to work on AIX. If not, they are obligated to make the source code available to you on request. Either way, getting hold of AIX compatible source code should not be a problem.
Upvotes: 2
Reputation: 26481
What you could attempt is something like this:
# setup a link that points to the youngest file
$ for f in *; do [[ ( ! -f last ) || ( "$f" -nt last) ]] && ln -sf "$f" last; done
# monitor that file continuously by filename
$ tail -F last
run the following in another shell
while :; for f in *; do [ "$f" -nt last ] && ln -sf "$f" last; done
You can also run this in a single command as:
while :; do for f in *; do [[ ( ! -f last ) || ($f -nt last) ]] && ln -sf $f last; done; done & tail -F last
Upvotes: 2