Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

Is there a way to remote tail 2 files?

I have two servers(a and b) behind a load balancer and I would like to do something like this if possible:

tail -f admin@serverA:~/mylogs/log admin@serverB:~/mylogs/log

Thanks!

share|improve this question
    
Why did you erase the answer? –  Pablo Fernandez Feb 13 '10 at 0:20
    
mostly because it did not work :-) –  mat Feb 13 '10 at 0:20
    
@mat Oh I was just about to try it :). Thanks anyways! –  Pablo Fernandez Feb 13 '10 at 0:25
    
it does not work because the <(foo) construct will wait for the inner command to finish before being replaced by a pipe in the original command line from which the software will be able to read, and, tail would never finish :-) –  mat Feb 13 '10 at 0:28
add comment

10 Answers

up vote 10 down vote accepted

This worked for me:

ssh -n user@hostname1 'tail -f /mylogs/log' &
ssh -n user@hostname2 'tail -f /mylogs/log' &
share|improve this answer
    
Yep, that's how i do it, except i usually have multiple gnome-terminals open, each with one session inside it –  Tom O'Connor Feb 13 '10 at 8:27
1  
Is there a way to do this without opening multiple independent ssh sessions? –  tgies Mar 20 '13 at 1:09
add comment

I was thinking it might also be possible to use:

ssh -f user@hostname1 "tail -f /var/log/file" > /tmp/somefile &
ssh -f user@hostname2 "tail -f /var/log/file" > /tmp/somefile &

The -f option after ssh allows you to enter a password before it runs in the background. Then you could have the line-by-line results in a single file and running:

tail -f /tmp/somefile

Would give you a little more control over the current "tail" command in case you wanted to use other tail options for displaying output.

share|improve this answer
add comment

Check out this answer on stackoverflow -- it uses dsh and tail -f.

share|improve this answer
add comment

My preferred option is to go with multitail. I'd run something like:

multitail -l 'ssh user@host1 "tail -f /some/log/file"' -l 'ssh user@host2 "tail -f /some/log/file"'
share|improve this answer
add comment

Take a look at multitail. Fust like the examples above, you can give it as a command to ssh, and then you will end up with one screen displaying (and buffering for easy scrollbacks) multiple logs. It also does coloring, which is very useful for spotting anomalies.

share|improve this answer
add comment

You can Tail files remotely using bash and rsync, I"m using it and it is a great bash script have a look at the following tutorial

Tail files remotely using bash and rsync

share|improve this answer
add comment

You can use fabric to tail several hosts (and also grep results, if needed):

$ fab -P -u 'USER' -p 'PASSWORD' --linewise -H host1,host2,host3 -- tail -f /path/to/my/log.log | grep ERROR
share|improve this answer
add comment

What would you say about something like this? http://gist.github.com/303175

share|improve this answer
add comment

Just a weird solution, but it works!:

Screen 1

ssh user@hostname1 "tail -f /var/log/file" > /dev/pts/6

Screen 2

ssh user@hostname2 "tail -f /var/log/file" > /dev/pts/6
share|improve this answer
add comment

or you can use screen to create two terminals and then split them.

SSH into the first host you want to tail the log file of and before running tail, enter screen.

Then tail the file on this host.

CTRL+A, c will create a new screen or window. From this new window ssh into the 2nd host and tail the file there.

Now to create the split screen

CTRL+A, SHIFT+S, this will create a split screen with current shell in the top part and the bottom part empty. To switch to the bottom part and put the first screen within it,

CTRL+A, TAB, this will move you to the bottom part. Now to bring your first SSH session into this area:

CTRL+A, " (quote symbol) and select the first session and hit enter.

I realize this may look like a lot of gymnastics, and it is, but you do get use to it once you use it a few times.

Here is a really good tutorial or quick reference to screen's commands: http://www.pixelbeat.org/lkdb/screen.html

Additionally, you can create a .screenrc file so that much of what I described can be automated the first time you enter screen.

Another nice thing about this is that you can just close your session and resume it some place else. For example, you're at work and you have some monitoring going on. You can just close your session without logging out, and resume when you get home or to another location.

share|improve this answer
add comment

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.