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?

4 Answers 4

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)'
1
  • Well, that's easier than my way! (lol, just upvoted an answer that's not mine, I'll leave mine up for curiosity's sake)
    – Jeremy
    Oct 19, 2010 at 8:11
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

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).

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
1
  • 1
    This doesn't actually use the fifo; you probably want the tail commands to be tail fileN >> pipeName. Feb 25, 2011 at 1:51

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .