Watch file using multitail even if it has not been created

logsmultitail

I've a MapServer logfile; it is created in /tmp/mapserv.log, but obviously it is flushed at every reboot, and is created only when a loggable event occurs.

I'm already using Multitail, but now I need to watch the folder /tmp for a file that has not even been created, waiting for it to appear.

Any hint?

Best Answer

You could perhaps use the -iw option. It check for new files matching a given pattern at a given interval. When one is found start following it.

E.g.:

multitail -iw /tmp/mapserv.log 2

Would look for the file /tmp/mapserv.log every 2 seconds. If and when it appears follow it.

It is meant to take a wildcard as in

-iw "/tmp/map*" 2 
# Quotes needed to prevent the shell to expand the pattern.

but works for non-wildcard as well. The number is how often to check for new files matching the pattern.


Else, touch could perhaps work. Might require something like su user -c 'touch ...' or a chown etc after touch.

If MapServer deletes existing mapserv.log on first logging and not truncate or append you would perhaps also need the -f option, as in:

Follow the following filename, not the descriptor.

Related Question