使用python从其他实例运行bash命令

时间:2014-02-14 12:45:47

标签: python amazon-web-services

我想从其他实例

使用python运行bash命令

我可以使用子进程本地调用命令

subprocess.call(myfile.sh)

我想从其他实例调用myfile.sh

1 个答案:

答案 0 :(得分:1)

看过你的评论如下:

import paramiko

client = paramiko.SSHClient()
#client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
client.connect(host_ip, username=your_username, password=your_password)
ftp = client.open_sftp()
ftp.put(myfile.sh)
stdin, stdout, stderr = client.exec_command(sh myfile) #or sh myfile.sh I think
print stdout