簡體   English   中英

在Python 3.4.3中使用Paramiko運行多個SSH命令

[英]Running Multiple SSH Commands Using Paramiko in Python 3.4.3

我正在嘗試在一個盒子上運行多個命令,但只有第一個命令成功。 這似乎與fork有關,但我無法弄清楚如何解決這個問題。 您的幫助或指導將不勝感激。

我的腳本


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 ")

OUTPUT:


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

如果您認為fork是問題,請嘗試使用Transport類的atfork() 方法

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM