【发布时间】:2017-11-02 10:04:50
【问题描述】:
我使用 pexpect 登录瞻博网络防火墙并发送相同的命令两次,我希望输出(我的意思是 s.before)应该是相同的,但它们不是。为什么 pexpect 在同一命令上表现不同?
下面是python测试文件。
import pxssh
import getpass
try:
s = pxssh.pxssh()
hostname = '192.168.215.254'
username = 'root'
password = 'engine@1'
s.login (hostname, username, password, original_prompt='root@developfirewall%', auto_prompt_reset=False)
s.sendline ('cli') # run a command
s.PROMPT = 'root@developfirewall>'
s.prompt() # match the prompt
print s.before # print everything before the prompt.
s.sendline ('configure')
s.PROMPT = 'root@developfirewall#'
s.prompt()
print s.before
print 'start---------------------------------------------'
s.sendline ('delete interfaces ge-0/0/5 unit 0 family inet address 10.123.0.13/32')
s.prompt()
print s.before
print 'end---------------------------------------------'
print 'start---------------------------------------------'
s.sendline ('delete interfaces ge-0/0/5 unit 0 family inet address 10.123.0.13/32')
s.prompt()
print s.before
print 'end---------------------------------------------'
s.logout()
except pxssh.ExceptionPxssh, e:
print "pxssh failed on login."
print str(e)
下面是标准输出,我可以看到相同的删除命令返回不同的响应。
cli
configure
Entering configuration mode
Users currently editing the configuration:
root terminal p1 (pid 64918) on since 2017-11-02 15:18:07 UTC, idle 01:34:05
[edit]
root terminal p0 (pid 64649) on since 2017-11-02 14:38:45 UTC, idle 02:07:38
[edit]
root terminal p4 (pid 64737) on since 2017-11-02 14:56:05 UTC, idle 01:55:21
[edit]
The configuration has been changed but not committed
[edit]
start---------------------------------------------
delete interfaces ge-0/0/5 unit 0 family inet addres
end---------------------------------------------
start---------------------------------------------
...0/5 unit 0 family inet address 10.123.0.13/32
delete interfaces ge-0/0/5 unit 0 family inet address 10.123.0.13/32warning: statement not found
[edit]
end---------------------------------------------
下面是对juniper防火墙的手动操作,对两个delete命令的响应是一样的。
[clouder@sky27 ~]$ ssh root@juniperfw
--- JUNOS 12.1X44-D35.5 built 2014-05-19 21:36:43 UTC
root@developfirewall% cli
root@developfirewall> configure
Entering configuration mode
Users currently editing the configuration:
root terminal p1 (pid 64918) on since 2017-11-02 15:18:07 UTC, idle 01:37:27
[edit]
root terminal p4 (pid 64737) on since 2017-11-02 14:56:05 UTC, idle 01:58:43
[edit]
The configuration has been changed but not committed
[edit]
root@developfirewall# delete interfaces ge-0/0/5 unit 0 family inet address 10.123.0.13/32
warning: statement not found
[edit]
root@developfirewall# delete interfaces ge-0/0/5 unit 0 family inet address 10.123.0.13/32
warning: statement not found
[edit]
root@developfirewall#
【问题讨论】: