![](/img/trans.png)
[英]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.