拖尾多个远程文件

Pab*_*dez 47 linux console logging tail

有没有办法远程tail 2文件?

我在负载均衡器后面有两台服务器(a 和 b),如果可能的话,我想做这样的事情:

tail -f admin@serverA:~/mylogs/log admin@serverB:~/mylogs/log
Run Code Online (Sandbox Code Playgroud)

谢谢!

mil*_*dos 38

我的首选选择是使用多尾。我会运行类似的东西:

multitail -l 'ssh user@host1 "tail -f /some/log/file"' -l 'ssh user@host2 "tail -f /some/log/file"'
Run Code Online (Sandbox Code Playgroud)


ein*_*ien 31

这对我有用:

ssh -n user@hostname1 'tail -f /mylogs/log' &
ssh -n user@hostname2 'tail -f /mylogs/log' &
Run Code Online (Sandbox Code Playgroud)

  • 但这不允许您使用“Ctrl+C”停止拖尾。 (9认同)

小智 8

您可以使用结构来跟踪多个主机(如果需要,还可以使用grep 结果):

$ fab -P -u 'USER' -p 'PASSWORD' --linewise -H host1,host2,host3 -- tail -f /path/to/my/log.log | grep ERROR
Run Code Online (Sandbox Code Playgroud)


小智 6

我在想也可以使用:

ssh -f user@hostname1 "tail -f /var/log/file" > /tmp/somefile &
ssh -f user@hostname2 "tail -f /var/log/file" > /tmp/somefile &
Run Code Online (Sandbox Code Playgroud)

ssh 后面的 -f 选项允许您在后台运行之前输入密码。然后,您可以将逐行结果保存在单个文件中并运行:

tail -f /tmp/somefile
Run Code Online (Sandbox Code Playgroud)

如果您想使用其他尾部选项来显示输出,将使您对当前的“tail”命令有更多的控制。


mrm*_*mrm 6

在 stackoverflow 上查看这个答案——它使用 dsh 和 tail -f。


Mar*_*cin 5

看看multitail。就像上面的例子一样,你可以将它作为一个命令发送给 ssh,然后你最终会在一个屏幕上显示(并缓冲以方便回滚)多个日志。它还进行着色,这对于发现异常非常有用。