我有一个简短的python脚本(最终会更大),该脚本可以在远程主机上远程执行“ pwd”命令。我只是在测试使用SSH密钥连接到主机(是的,它们设置正确)。到目前为止,我所拥有的似乎工作正常,但是它只是挂在IDLE窗口中...不会出错,但是如果我检查主机的上次登录日期,则在执行脚本时它不匹配。有没有一种方法可以显示输出(类似于预期,所以我可以查看我是否实际上还在登录)。
试图改用密码,完全相同的行为。
#!/usr/bin/python
from fabric import Connection
sshConnection = Connection(
host = 'hostname.com',
user='myuser',
connect_kwargs={
"key_filename":r'C:\Users\user\Desktop\id_rsa',
},
)
sshConnection.run('pwd')
close()
基本上可以在“ IDLE”窗口中找到它
> 重新启动:/PATH/TO/SCRIPT/ON/WINDOWS/LAPTOP/script.py |
答案 0 :(得分:0)
I advise you to use fabric2.4.0
and Python 3
from fabric import Connection as connection, task
@task
def deploy(ctx):
with connection(host=host, user=user) as c:
c.run('pwd')
Put the code above in a file called fabfile.py and you run it from your command line
fab deploy