14

I have a web application that outputs to a number of log files with performance information. One log file outputs code execution times and another outputs SQL timings. I have no control over the logger or the code that produces the log files, but I want to output the logs in one place.

Currently I am doing something like this

tail -f sqlLogs.log | grep sql-time
tail -f perflogs.log | grep exec-time

This outputs something to the console every time an SQL is executed in the application. But I have to run the code in two separate SSH sessions. However, what I want to be able to tail both files, in the same SSH session. Is this possible?

Codemwnci
  • 1,259

4 Answers4

20

Yes, tail outputs lines appended to all the files given on the command line:

tail -F sqlLogs.log perflogs.log | egrep '(sql-time|exec-time)'
4

Have a look at MultiTail. It's your friend.

You can have the multiple log tails in

 - different windows, a al vim's 'split'
 - or have it merge the two (or N) streams into one view and
 - you can filter steams by regex and, if you like,
 - it will 'tee' the output to a file

http://www.vanheusden.com/multitail/

On Ubuntu 10.04: sudo apt-get install multitail

Jorge Castro
  • 73,717
2

Yep, using the screen command, you can have 2 bash sessions running on one terminal.

  • Run screen to get started,
  • Then type Ctrl-a then S (NOTE: capital S) to split the screen into 2.
  • Ctrl-a then Tab will move you between the two sessions.
  • Ctrl-a then c will start a shell in that new region.

(Please see Riccardo's answer before using this, his is much simpler, I'll leave this up as it may be useful for people with similar but different problems).

Jeremy
  • 2,926
0

You can use mkfifo to multiplex the output to one pipe

create a fifo pipe, tail n files to the pipe, then cat the pipe

 mkfifo pipeName
 tail file1 &
 tail file2 &
 ...
 tail fileN &
 cat pipeName

when finished

 rm pipeName
dvhh
  • 131