Paramiko SSH python

假如想象 提交于 2021-01-29 16:53:02

问题


I´m trying the simplest way to make a SSH connection and execute a command with paramiko

import paramiko, base64
client = paramiko.SSHClient()
client.load_system_host_keys()
client.connect('10.50.0.150', username='XXXXX', password='XXXXXX')
stdin, stdout, stderr = client.exec_command('show performance -type host-io')
for line in stdout:
    print '... ' + line.strip('\n')
client.close()

------------ERROR-----------------------

Traceback (most recent call last):
  File "a.py", line 5, in <module>
    stdin, stdout, stderr = client.exec_command('show performance -type host-io')
  File "/usr/lib/python2.6/site-packages/paramiko-1.10.1-py2.6.egg/paramiko/client.py", line 374, in exec_command
    chan.exec_command(command)
  File "/usr/lib/python2.6/site-packages/paramiko-1.10.1-py2.6.egg/paramiko/channel.py", line 218, in exec_command
    self._wait_for_event()
  File "/usr/lib/python2.6/site-packages/paramiko-1.10.1-py2.6.egg/paramiko/channel.py", line 1122, in _wait_for_event
    raise e
EOFError

If i execute this code changing the command it works and to another computer, this command works fine via SSH interative shell.

Any idea ?


回答1:


After client.connect(. . .) you need to use this command

session = client.get_transport().open_session()

then use session.exec_command(. . .).



来源:https://stackoverflow.com/questions/17964414/paramiko-ssh-python

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!