- 论坛徽章:
- 0
|
代码如下:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import pxssh,os
def nasssh(nas_ip):
cmd =['cluster show','system stat sys']
s=pxssh.pxssh()
uesrname='sa'
password='god'
s.login(nas_ip,uesrname,password)
s.prompt()
print 'normal login'
for i in cmd:
s.sendline(i)
s.prompt()
print s.before
s.sendline('logout')
s.prompt()
print s.before
print 'normal exit'
nasssh('192.168.100.4')
错误信息:
当把cmd里的指令执行完毕后,报错如下:
oss5nas> system stat sys
Gathering statistics...
Node %cpu_util %mem_util av_read_time(ms) av_write_time(ms) rx_av_pubeth(M
B/s) tx_av_pubeth(MB/s)
---- --------- --------- ---------------- ----------------- --------------
--- ------------------
oss5nas_01 1.390 98.460 0.433 0.290 0.030
0.030
oss5nas_02 3.340 11.640 1.438 1.855 0.000
0.015
oss5nas>
Traceback (most recent call last):
File "./test.py", line 30, in <module>
nasssh('192.168.100.4')
File "./test.py", line 26, in nasssh
s.prompt()
File "/usr/lib/python2.6/site-packages/pexpect/pxssh.py", line 359, in prompt
i = self.expect([self.PROMPT, TIMEOUT], timeout=timeout)
File "/usr/lib/python2.6/site-packages/pexpect/__init__.py", line 1451, in expect
timeout, searchwindowsize)
File "/usr/lib/python2.6/site-packages/pexpect/__init__.py", line 1466, in expect_list
timeout, searchwindowsize)
File "/usr/lib/python2.6/site-packages/pexpect/__init__.py", line 1554, in expect_loop
raise EOF(str(err) + '\n' + str(self))
pexpect.EOF: End Of File (EOF). Empty string style platform.
<pexpect.pxssh.pxssh object at 0x81010cc>
version: 3.3
command: /usr/bin/ssh
args: ['/usr/bin/ssh', '-q', '-l', 'master', '192.168.100.4']
searcher: <pexpect.searcher_re object at 0x8188e6c>
buffer (last 100 chars): ''
before (last 100 chars): ' 11.640 1.438 1.855 0.000 \r\n 0.015 \r\noss5nas> logout\r\n'
after: <class 'pexpect.EOF'>
match: None
match_index: None
exitstatus: 0
flag_eof: True
pid: 20079
child_fd: 3
closed: False
timeout: 10
delimiter: <class 'pexpect.EOF'>
logfile: None
logfile_read: None
logfile_send: None
maxread: 2000
ignorecase: False
searchwindowsize: None
delaybeforesend: 0.05
delayafterclose: 0.1
delayafterterminate: 0.1
#
谢谢!
|
|