python2.7 paramiko-脚本的远程运行

问题描述

我正在尝试使用paramiko连接并执行远程脚本。在下面的代码中,client.exec_command中的脚本是否只能包含linux命令(如ls -l)?

Ubuntu BOX A中的代码:

client = paramiko.SSHClient()
client.load_system_host_keys()
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())

client.connect('ip-address of Ubuntu BOX B',22,'username','password')   <<<<< no issues till here....
stdin,stdout,stderr = client.exec_command('./shut.sh') 

for line in stdout:
   print 'This is the normal value ==> ' + line.strip('\n')

for line in stderr:
   print 'This is the err value ==> ' + line.strip('\n')

client.close()

运行上面的代码时,出现“找不到awsstop命令”。

我的远程脚本(shut.sh)包含ZPDT shutdown命令,我在其中关闭了zpdt系统。

Ubuntu Box B中的Shut.sh

#!/bin/sh
awsstop

但是,当我通过以下python代码在本地运行shut.sh时,它会按预期工作。

在Ubuntu Box B中的test.py

import os
import subprocess
subprocess.Popen(["/home/ibmsys1/shut.sh"])

无论如何,我们可以远程触发此脚本,还是paramiko无法执行此操作?我们还有其他选择吗?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...