码迷,mamicode.com
首页 > 其他好文 > 详细

pxssh远程执行命令出错处理

时间:2014-12-19 15:59:04      阅读:201      评论:0      收藏:0      [点我收藏+]

标签:pxssh

测试环境: Ubuntu12.04

python-pexpect安装: apt-get install python-pexpect


测试脚本:

#!/usr/bin/env python
import pxssh
import getpass
try:
    s = pxssh.pxssh()
    hostname = raw_input(‘hostname: ‘)
    username = raw_input(‘username: ‘)
    password = getpass.getpass(‘please input password: ‘)
    s.login(hostname, username, password)
    s.sendline(‘uptime‘)
    s.prompt()
    print s.before
    s.sendline(‘ls -l‘)
    s.prompt()
    print s.before
    s.sendline(‘df‘)
    s.prompt()
    print s.before
    s.logout()
except pxssh.ExceptionPxssh, e:
    print "pxssh failed on login."
    print str(e)

执行时会报错:

Traceback (most recent call last):

  File "pxsshsimple1.py", line 9, in <module>

    s.login (hostname, username, password)

  File "/usr/lib/python2.7/dist-packages/pxssh.py", line 243, in login

    if not self.synch_original_prompt():

  File "/usr/lib/python2.7/dist-packages/pxssh.py", line 134, in synch_original_prompt

    self.read_nonblocking(size=10000,timeout=1) # GAS: Clear out the cache before getting the prompt

  File "/usr/lib/python2.7/dist-packages/pexpect.py", line 824, in read_nonblocking

    raise TIMEOUT (‘Timeout exceeded in read_nonblocking().‘)

pexpect.TIMEOUT: Timeout exceeded in read_nonblocking().


修改/usr/lib/python2.7/dist-packages/pxssh.py文件,在line134行前增加:

        self.sendline()
        time.sleep(0.5)


pxssh远程执行命令出错处理

标签:pxssh

原文地址:http://188533.blog.51cto.com/178533/1591710

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!