Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/301.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/ssh/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在Python 3.4.3中使用Paramiko运行多个SSH命令_Python_Ssh_Command_Paramiko - Fatal编程技术网

在Python 3.4.3中使用Paramiko运行多个SSH命令

在Python 3.4.3中使用Paramiko运行多个SSH命令,python,ssh,command,paramiko,Python,Ssh,Command,Paramiko,我试图在一个框上运行多个命令,但只有第一个命令成功。这似乎与fork有关,但我不知道如何解决这个问题。我们将非常感谢您的帮助或指导 我的剧本 导入paramiko #用python 3.4.3制作 ssh=paramiko.SSHClient() ssh.set_缺少_主机_密钥_策略(paramiko.AutoAddPolicy()) ssh.connect('xxx.xx.xx.xx',port=22,username='domain\myusername',password='mypas

我试图在一个框上运行多个命令,但只有第一个命令成功。这似乎与fork有关,但我不知道如何解决这个问题。我们将非常感谢您的帮助或指导

我的剧本
导入paramiko
#用python 3.4.3制作
ssh=paramiko.SSHClient()
ssh.set_缺少_主机_密钥_策略(paramiko.AutoAddPolicy())
ssh.connect('xxx.xx.xx.xx',port=22,username='domain\myusername',password='mypassword')
stdin、stdout、stderr=ssh.exec_命令(“vol status-f”)#这是第一个命令,可以正常工作
output=stdout.readlines()
打印(“\n”.join(输出))
stdin,stdout,stderr=ssh.exec_命令('disk show-n'))
output1=stdout.readlines()
打印(“\n”。连接(输出1))
#stdin,stdout,stderr=ssh.exec_命令('vol status-s')
#stdin,stdout,stderr=ssh.exec_命令('df-Ag'))
ssh.close()
输入(“按下退出”)
输出:

回溯(最近一次呼叫最后一次):
文件“C:\Users\myusername\Desktop\folder\u copy\test.py”,第13行,在
stdin,stdout,stderr=ssh.exec_命令('disk show-n'))
exec_命令第401行的文件“C:\Python34\lib\site packages\paramiko-1.16.0-py3.4.egg\paramiko\client.py”
chan=自我传输。打开会话(超时=超时)
文件“C:\Python34\lib\site packages\paramiko-1.16.0-py3.4.egg\paramiko\transport.py”,第702行,在open_会话中
超时=超时)
文件“C:\Python34\lib\site packages\paramiko-1.16.0-py3.4.egg\paramiko\transport.py”,第823行,在开放频道中
提高e
运行文件“C:\Python34\lib\site packages\paramiko-1.16.0-py3.4.egg\paramiko\transport.py”,第1726行
ptype,m=self.packetizer.read_message()
文件“C:\Python34\lib\site packages\paramiko-1.16.0-py3.4.egg\paramiko\packet.py”,第386行,在read_消息中
header=self.read\u all(self.\u块大小\u in,check\u rekey=True)
文件“C:\Python34\lib\site packages\paramiko-1.16.0-py3.4.egg\paramiko\packet.py”,第251行,全部读取
提高EOR()
伊奥费罗


如果您认为fork是问题所在,请尝试Transport类的
atfork()

如果您认为fork是问题所在,请尝试Transport类的
atfork()

@RyanS…感谢您的回复。我没有使用过
atfork()
,但会尝试一下。@RyanS…谢谢您的回复。我没有使用过
atfork()
,但会尝试一下。
import paramiko
#Made in python 3.4.3

ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())

ssh.connect('xxx.xx.xx.xx', port=22, username='domain\myusername', password='mypassword')

stdin, stdout, stderr = ssh.exec_command('vol status -f') #this being the first command works fine
output = stdout.readlines()
print ("\n".join(output))

stdin, stdout, stderr = ssh.exec_command('disk show -n')
output1 = stdout.readlines()
print ("\n".join(output1))
#stdin, stdout, stderr = ssh.exec_command('vol status -s')
#stdin, stdout, stderr = ssh.exec_command('df -Ag')

ssh.close()
input("Press <Enter> to exit ")
Traceback (most recent call last):
  File "C:\Users\myusername\Desktop\folder_copy\test.py", line 13, in <module>
    stdin, stdout, stderr = ssh.exec_command('disk show -n')
  File "C:\Python34\lib\site-packages\paramiko-1.16.0-py3.4.egg\paramiko\client.py", line 401, in exec_command
    chan = self._transport.open_session(timeout=timeout)
  File "C:\Python34\lib\site-packages\paramiko-1.16.0-py3.4.egg\paramiko\transport.py", line 702, in open_session
    timeout=timeout)
  File "C:\Python34\lib\site-packages\paramiko-1.16.0-py3.4.egg\paramiko\transport.py", line 823, in open_channel
    raise e
  File "C:\Python34\lib\site-packages\paramiko-1.16.0-py3.4.egg\paramiko\transport.py", line 1726, in run
    ptype, m = self.packetizer.read_message()
  File "C:\Python34\lib\site-packages\paramiko-1.16.0-py3.4.egg\paramiko\packet.py", line 386, in read_message
    header = self.read_all(self.__block_size_in, check_rekey=True)
  File "C:\Python34\lib\site-packages\paramiko-1.16.0-py3.4.egg\paramiko\packet.py", line 251, in read_all
    raise EOFError()
EOFError