Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I wanted to combine two continuous text streams generated by tail -f into one and watch them in the same screen. Is it possible? Both text streams are line-oriented (e.g. logs), if that helps.

Update: just to make it clear, the two tail -f streams are not on local files but from two remote SSH sessions, e.g. ssh remote-host tail -f file.log

share|improve this question

3 Answers 3

tail supports several files, for example:

tail -q -f file1 file2
share|improve this answer
    
Thanks very much for the answer! I wasn't very clear in the original question. I just updated the description to make it more specific about streams over SSH. –  Riobard Jun 19 '13 at 16:20

If you just want to watch the log lines, and don't need the data afterwards, why not:

ssh host1 tail -f file & ssh host2 tail -f file &

To accomplish what you say in the comment, if you have the pee command (moreutils):

pee 'ssh host1 tail -f file' 'ssh host2 tail -f file' < /dev/null
share|improve this answer
    
Thanks! I was hoping there is a tool to combine two remote streams into one locally, so viewing them is easier (without creating tmp files), but more importantly I can then pipe them together to another downstream process. –  Riobard Jun 22 '13 at 23:27

The quick and dirty way that comes to mind is to tail each log file on each remote machine and redirect them to temporary files locally. Then, tail both logs with the method golimar suggested.

  1. ssh user@host1 -C tail -f /path/to/log >> /tmp/log1.tmp
  2. ssh user@host2 -C tail -f /path/to/log >> /tmp/log2.tmp
  3. tail -q -f /tmp/log1.tmp /tmp/log2.tmp

It's not pretty, requires keeping local data, and requires the first 2 commands to be background'ed (or run in screen or similar), but it should get the job done!

share|improve this answer
    
Thanks! This works. I was hoping there might be some rare commands/options that I could do it in one line without creating tmp files. –  Riobard Jun 19 '13 at 23:31
    
if the files are in the same server you could do ssh user@host -C tail -q -f /path/to/log1 /path/to/log2 –  Miguel Jul 17 at 20:15

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.