我正在尝试使用Fabric(v1.3.4)在各种服务器上配置Karaf实例.Karaf实现了SSH服务器.所以,我在同一台服务器上运行了2个ssh守护进程; 一个在端口22上,一个在8101上.使用Fabric的fabric.tasks.execute()方法,我可以连接到另一个主机:port.
问题是,由于明显劫持了env.user,我的初始会话被第二个连接的指定用户劫持.
这是一个简化的fabfile.py示例:
from fabric.api import env, run
from fabric.tasks import execute
env.hosts = ['192.168.5.250']
def firstSSH():
run("echo first")
executeHosts = []
for host in env.hosts:
executeHosts.append("notmmaley@" + host + ":8101")
execute(secondSSH, hosts=executeHosts)
run("echo first again")
def secondSSH():
run("echo second", shell=False, pty=False)
Run Code Online (Sandbox Code Playgroud)
两台SSH服务器位于同一台服务器上,在两个不同的端口上,允许两个不同的用户.这是输出:
~/fabric$ fab firstSSH
[192.168.5.250] Executing task 'firstSSH'
[192.168.5.250] run: echo first
[192.168.5.250] Login password:
[192.168.5.250] out: first
[notmmaley@192.168.5.250:8101] Executing task 'secondSSH'
[notmmaley@192.168.5.250:8101] run: echo second
[notmmaley@192.168.5.250:8101] Login password:
[notmmaley@192.168.5.250:8101] out: second
[notmmaley@192.168.5.250:8101] run: echo first again …Run Code Online (Sandbox Code Playgroud)