5

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

8

tail supports several files, for example:

tail -q -f file1 file2
  • 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
4

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
  • 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
2

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!

  • 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 '14 at 20:15
1

You can checkout in'side log.

A Java tool I created, able to read local and distant log files using SSH. It is fairly simple to use.

Some more explanations: https://github.com/pschweitz/insidelog/wiki

Just download version corresponding to your operating system, of native jar release executable within your Java Runtime (requires java 8_40 or higher):

https://github.com/pschweitz/insidelog/releases

You can find a complete documentation (embedded with and in Github's page as well)

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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