我有一个开关,可以在其中显示带有match的配置:
admin@sele> show configuration | display set | match " ge-0/0/1 "
set interfaces ge-0/0/1 unit 0 family ethernet-switching interface-mode access
set interfaces ge-0/0/1 unit 0 family ethernet-switching vlan members vlan106
set interfaces ge-0/0/1 unit 0 family ethernet-switching filter input Interface-Limit-100m
set class-of-service interfaces ge-0/0/1 shaping-rate 100m
{master:0}
admin@sele>
配置数据为:
set interfaces ge-0/0/1 unit 0 family ethernet-switching interface-mode access
set interfaces ge-0/0/1 unit 0 family ethernet-switching vlan members vlan106
set interfaces ge-0/0/1 unit 0 family ethernet-switching filter input Interface-Limit-100m
set class-of-service interfaces ge-0/0/1 shaping-rate 100m
现在我要使用pexpect
来获取配置数据
import pexpect
child = pexpect.spawn('ssh root@14.54.24.9')
child.expect('Password:')
child.sendline('password')
child.expect('#')
child.sendline('ssh admin@10.10.10.1')
child.expect('Password:')
child.sendline('my juniper switch password')
child.expect('>')
print('ldl1: ' ,child.before)
child.sendline('show configuration | display set | match " ge-0/0/1 "')
print('ldl2: ' ,child.before)
print('ldl2: ' ,child.after)
print('ldl2: ' ,child.buffer)
日志:
ldl1: b'\r\n--- JUNOS 14.1X53-D47.3 built 2018-05-11 01:30:52 UTC\r\n{master:0}\r\nadmin@sele'
ldl2: b'\r\n--- JUNOS 14.1X53-D47.3 built 2018-05-11 01:30:52 UTC\r\n{master:0}\r\nadmin@sele'
ldl2: b'>'
ldl2: b' '
我无法获取配置数据。
EDIT-01
我使用5秒钟的睡眠时间,但这仍然是问题,之前或之后都没有收到日志。
import time
...
child.sendline('show configuration | display set | match " ge-0/0/1 "')
time.sleep(5)
print('ldl2: ' ,child.before)
print('ldl2: ' ,child.after)
print('ldl2: ' ,child.buffer)