I’m using RHEL 4.
The normal tail -F file_name*.log doesn’t update when the time flips over to 0000.
Here’s what I’ve tried so far from searching the web, both of which try to use nested tail:
tail -F $(ls -tr file_name*.log | tail -n 1)
tail -F $(fine . -maxdepth 1 -type f -printf "%[email protected] %pn" | sort -n | tail n 1 | cut -d' ' -f 2-)
None of these flip over to new files. Plain old tail -F file_name*.log works in my small test cases (while the 2 above don’t), but it doesn’t work when I’m tailing a real log file.
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
tail monitors a single file, or at most a set of files that is determined when it starts up. In the command tail -F file_name*.log, first the shell expands the wildcard pattern, then tail is called on whatever file(s) exist at the time.
To monitor a set of files based on wildcards, you can use multitail.
multitail -iw 'file_name*.log' 1
Method 2
This won’t (can’t) work – the sub-shells you’re using to determine the latest file only get executed once. The glob won’t work because the shell evaluates the wild-card only ONCE.
One way to deal with it would be to use ‘watch’ to run the whole thing, but that would hack up the output every so many seconds.
Method 3
You’re probably going to have to write something to follow tail. Or configure your system to not roll logs (or that log) at midnight. Either way, the filehandle of the tailed logfile is reset when it’s rolled.
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0