8

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?

Gilles 'SO- stop being evil'
  • 807,993
  • 194
  • 1,674
  • 2,175
fradeve
  • 243
  • 2
  • 4
  • Could you `touch` it before starting multitail? (Edited Q) – Runium Apr 18 '13 at 10:43
  • Of course I could write a script or Bash alias to touch it before starting multitail, although I've never tried to run MapServer with an already present logfile (it should append results to it); I'm searching for a more "clean" solution or a specific multitail feature, but, yes. – fradeve Apr 18 '13 at 10:56

2 Answers2

6

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.

Runium
  • 28,133
  • 5
  • 50
  • 71
0

This is an OOOOLLLLD question, but the best answer has changed:

Use the --retry-all switch like this:

multitail --retry-all file1.log file2.log [...]

You should see the man page for full details, but in short, all files after --retry-all are retried similar to tail's -F/--retry switches.