This is an interesting question and the simple answer should be: Use the prefix switch with tail, but unfortunately this is currently not implemented in most versions of tail
.
As I see it, you have two options: adapt the standard tools to the task (see Udys answer) or write your own tool with your favorite scripting/programming language.
Below is one way you could do it with the File::Tail::Multi
module for perl
. Note that you may need to install the module from CPAN (cpan -i File::Tail::Multi
).
Save the following script e.g. mtail
to your executable path and make the script executable.
#!/usr/bin/env perl
use File::Tail::Multi;
$| = 1; # Enable autoflush
$tail = File::Tail::Multi->new(RemoveDuplicate => 0,
OutputPrefix => 'f',
Files => \@ARGV);
while(1) { $tail->read; $tail->print; sleep 2 }
Change OutputPrefix
to 'p'
if you prefer full path prefixes.
Run it like this:
mtail /var/links/proc2/id/myprocess*/Daily/myprocess*.log | grep --line-buffered "Search this: "
You do not need to specify --line-buffered
when grep
is the last command, so this is sufficient:
mtail /var/links/proc2/id/myprocess*/Daily/myprocess*.log | grep "Search this: "