当我尝试多个命令通过其他ssh内的ssh远程执行命令时,我得到了奇怪的结果。
来自man ssh:
-t
强制伪终端分配。这可以用来执行 远程计算机上的任意基于屏幕的程序,这可能非常 有用的,例如实施菜单服务时。多个-t选项 强制tty分配,即使ssh没有本地tty。
如果我愿意
ssh -t root@host1 ssh root@host2 "cat /etc/hostname && cat /etc/hostname"
或
ssh -t root@host1 ssh -t root@host2 "cat /etc/hostname && cat /etc/hostname"
在两种情况下我都能得到
host1
Connection to host1 closed.
host2
Connection to host2 closed.
我想要这个结果:
host1
host1
Connection to host1 closed.
Connection to host2 closed.
我想在ssh中使用ssh在同一服务器上运行所有命令。
如果我仅使用一个ssh,它将起作用:
ssh -t root@host1 "cat /etc/hostname && cat /etc/hostname"
host1
host1
Connection to host1 closed.
答案 0 :(得分:0)
我可以使用它,但是我无法解释发生了什么事。
ssh -t root@host1 "ssh -t root@host2 \"cat /etc/hostname ; cat /etc/hostname\""
host1
host1
Connection to host1 closed.
Connection to host2 closed.
答案 1 :(得分:0)
这不是-t的工作方式。
您可以尝试:
ssh root@host1 .....; ssh root@host2 ....
否则,请使用将同时在两台服务器上执行正常运行时间命令的PSSH:
pssh -h hostfile -i uptime