tail multiple files and grep the output

212 picture 212 · Sep 30, 2013 · Viewed 19.8k times · Source

I would like to grep a pattern from multiple log files which are being constantly updated by some processes and tail the output of this grep continuosly. Below command doesnt work and I get

  • tail: warning: following standard input indefinitely is ineffective
tail -f  | grep --line-buffered "Search this: " /var/links/proc2/id/myprocess*/Daily/myprocess*.log

Can someone help sort this out?

Answer

Anshul Goyal picture Anshul Goyal · Sep 30, 2013

You should have a look at multitail tool (Install using sudo apt-get install multitail)

In short, with multitail, you need to use the --mergeall flag for viewing output of all in one place

multitail --mergeall /var/links/proc2/id/myprocess*/Daily/myprocess*.log  | grep --line-buffered "Search this: " 

You can do the same without using grep

multitail -E "Search this: " --mergeall /var/links/proc2/id/myprocess*/Daily/myprocess*.log  

To view the output individually using multitail, this will give the filename as well.

multitail -E "Search this: " /var/links/proc2/id/myprocess*/Daily/myprocess*.log