[英]How to run shell script as postgres on remote server using fabric python
[英]python script using fabric to remote execute is hanging at connection?
我有一个短的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窗口中得到它
> RESTART:/PATH/TO/SCRIPT/ON/WINDOWS/LAPTOP/script.py |
我建议你使用fabric2.4.0
和Python 3
from fabric import Connection as connection, task
@task
def deploy(ctx):
with connection(host=host, user=user) as c:
c.run('pwd')
将上面的代码放在名为fabfile.py的文件中,然后从命令行fab deploy
运行它
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.