6

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

4 Answers 4

8

tail supports several files, for example:

tail -q -f file1 file2
1
  • 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
    Commented Jun 19, 2013 at 16:20
5

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
1
  • 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
    Commented Jun 22, 2013 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!

2
  • 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
    Commented Jun 19, 2013 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
    Commented Jul 17, 2014 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)

0

You must log in to answer this question.

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