Python 我无法在多ssh环境中使用pexpect获取日志数据

Python 我无法在多ssh环境中使用pexpect获取日志数据,python,pexpect,Python,Pexpect,我有一个开关,可以在其中显示配置与匹配: 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

我有一个开关,可以在其中显示配置与匹配:

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)

您的shell示例在提示符(
admin@sele
)。pexpect输出表示dele(
admin@dele
)。都来自同一个设备?同一个设备,我更改了名称。在调用设备外壳上的命令的第二个
发送行
调用之后,请尝试期待
。您的代码中的打印可能发生在子进程收到结果之前。仍然不起作用,请检查我的编辑。您的shell示例在提示中显示设备名称为sele(
admin@sele
)。pexpect输出表示dele(
admin@dele
)。都来自同一个设备?同一个设备,我更改了名称。在调用设备外壳上的命令的第二个
发送行
调用之后,请尝试期待
。您的代码中的打印可能发生在子进程收到结果之前。如果仍然不起作用,请检查我的编辑。