The problem with tail -f
tail -f
is very useful to see real-time addition to log files. It allows watching all log files in specified folders, example: tail -f abc.log mydir/*.log
Problems:
abc.log
is ignored forever if it does not exist at the moment the command is launched (which is most of the time, since I usually delete all log files before launching thetail -f
command.- The
*
only expands at launch time, which means that if after 5 minutes a new file appears in the directory, it is ignored.
Requirements
- Take file path(s) and folder path(s) as input
- Output the content of these text files as soon as the content appears (as fast as possible)
- For folders, keep checking whether new files have been created in them
- For files that do not exist yet, keep checking whether they have been created
- Free and open source
- Bonus if maintained deb/rpm packages are available, double bonus if present in major distributions' channels.
Tailing several files could result in such output for instance if a.log is written then b.log then a.log again:
==> a.log <==
bla1
bla2
==> b.log <==
blb1
blb2
==> a.log <==
bla3
bla4
This is how tail
does it, but similar formatting is OK too.
while [ ! -f "MyFile" ]; do echo "waiting"; sleep 10; done; tail -f MyFile
For your "For folders" requirement, you'll need to explain what you want to happen if/when there's more than one such file.