我正在编写一个脚本来执行ping和traceroute,在这里我遇到了这样一种情况:如果在25秒内未收到完整的输出,并且我也想一直接收到它生成并执行必要的步骤。另一个条件是,如果我在traceroute输出中收到9跳。我想停止执行命令并验证我收到的输出。
我尝试了netmiko函数send_command_timing()和send_command_expect(),但它们都不满足我的要求。
j = 1
while not output and j <25:
output = connection.send_command_expect(command, expect_string=r'#')
time.sleep(1)
j += 1