gpt4 book ai didi

linux - 期望 ping 脚本跳过发送步骤

转载 作者:塔克拉玛干 更新时间:2023-11-03 01:05:10 24 4
gpt4 key购买 nike

在使用 expect 登录到远程交换机后,我尝试 ping 4 个不同的 IP 地址,登录部分工作正常,第一个 2 ping 命令(发送);但它会跳过第 3 个 ping 命令并进行第 4 个 ping。大多数情况下,在显示 ping 摘要之前它会退出脚本。

我的脚本:

 #!/usr/bin/expect
spawn telnet 192.168.xx.xx
expect "Username:"
send "username\r"
expect "Password:"
send "password\r"
expect ">"
send "ping -c 20 192.168.1.10\r"
expect ">"
send "ping -c 20 192.168.10.22\r"
expect ">"
send "ping -c 20 192.168.10.33\r"
expect ">"
send "ping -c 20 192.168.11.10\r"
expect ">"
send "quit\r" # command to exit from switch
expect eof

我尝试在每个发送命令之前添加“sleep 4”,但结果是一样的。

输出:

<switch>ping -c 20 192.168.1.20
PING 192.168.1.20: 56 data bytes, press CTRL_C to break
Reply from 192.168.1.20: bytes=56 Sequence=1 ttl=255 time=1 ms
Reply from 192.168.1.20: bytes=56 Sequence=2 ttl=255 time=1 ms
Reply from 192.168.1.20: bytes=56 Sequence=3 ttl=255 time=101 ms
Reply from 192.168.1.20: bytes=56 Sequence=4 ttl=255 time=2 ms
Reply from 192.168.1.20: bytes=56 Sequence=5 ttl=255 time=2 ms
Reply from 192.168.1.20: bytes=56 Sequence=6 ttl=255 time=2 ms
Reply from 192.168.1.20: bytes=56 Sequence=7 ttl=255 time=102 ms
Reply from 192.168.1.20: bytes=56 Sequence=8 ttl=255 time=2 ms
Reply from 192.168.1.20: bytes=56 Sequence=9 ttl=255 time=3 ms
Reply from 192.168.1.20: bytes=56 Sequence=10 ttl=255 time=1 ms
Reply from 192.168.1.20: bytes=56 Sequence=11 ttl=255 time=108 ms
Reply from 192.168.1.20: bytes=56 Sequence=12 ttl=255 time=1 ms
Reply from 192.168.1.20: bytes=56 Sequence=13 ttl=255 time=1 ms
Reply from 192.168.1.20: bytes=56 Sequence=14 ttl=255 time=2 ms
Reply from 192.168.1.20: bytes=56 Sequence=15 ttl=255 time=130 ms
Reply from 192.168.1.20: bytes=56 Sequence=16 ttl=255 time=1 ms
Reply from 192.168.1.20: bytes=56 Sequence=17 ttl=255 time=2 ms
Reply from 192.168.1.20: bytes=56 Sequence=18 ttl=255 time=1 ms
Reply from 192.168.1.20: bytes=56 Sequence=19 ttl=255 time=160 ms
Reply from 192.168.1.20: bytes=56 Sequence=20 ttl=255 time=1 ms

--- 192.168.1.20 ping statistics ---
20 packet(s) transmitted
20 packet(s) received
0.00% packet loss
round-trip min/avg/max = 1/31/160 ms

<switch>ping -c 20 192.168.10.22
PING 192.168.10.22: 56 data bytes, press CTRL_C to break
Reply from 192.168.10.22: bytes=56 Sequence=1 ttl=255 time=1 ms
Reply from 192.168.10.22: bytes=56 Sequence=2 ttl=255 time=12 ms
Reply from 192.168.10.22: bytes=56 Sequence=3 ttl=255 time=1 ms
Reply from 192.168.10.22: bytes=56 Sequence=4 ttl=255 time=35 ms
Reply from 192.168.10.22: bytes=56 Sequence=5 ttl=255 time=2 ms
Reply from 192.168.10.22: bytes=56 Sequence=6 ttl=255 time=16 ms
Reply from 192.168.10.22: bytes=56 Sequence=7 ttl=255 time=2 ms
Reply from 192.168.10.22: bytes=56 Sequence=8 ttl=255 time=29 ms
Reply from 192.168.10.22: bytes=56 Sequence=9 ttl=255 time=4 ms
Reply from 192.168.10.22: bytes=56 Sequence=10 ttl=255 time=39 ms
Reply from 192.168.10.22: bytes=56 Sequence=11 ttl=255 time=1 ms
Reply from 192.168.10.22: bytes=56 Sequence=12 ttl=255 time=57 ms
Reply from 192.168.10.22: bytes=56 Sequence=13 ttl=255 time=1 ms
Reply from 192.168.10.22: bytes=56 Sequence=14 ttl=255 time=1 ms
Reply from 192.168.10.22: bytes=56 Sequence=15 ttl=255 time=1 ms
Reply from 192.168.10.22: bytes=56 Sequence=16 ttl=255 time=1 ms
Reply from 192.168.10.22: bytes=56 Sequence=17 ttl=255 time=1 ms
Reply from 192.168.10.22: bytes=56 Sequence=18 ttl=255 time=2 ms
Reply from 192.168.10.22: bytes=56 Sequence=19 ttl=255 time=1 ms
Reply from 192.168.10.22: bytes=56 Sequence=20 ttl=255 time=2 ms

--- 192.168.10.22 ping statistics ---
20 packet(s) transmitted
20 packet(s) received
0.00% packet loss
round-trip min/avg/max = 1/10/57 ms

<switch>ping -c 20 192.168.11.10
PING 192.168.11.10: 56 data bytes, press CTRL_C to break
Reply from 192.168.11.10: bytes=56 Sequence=1 ttl=255 time=4 ms
Reply from 192.168.11.10: bytes=56 Sequence=2 ttl=255 time=1 ms
Reply from 192.168.11.10: bytes=56 Sequence=3 ttl=255 time=44 ms
Reply from 192.168.11.10: bytes=56 Sequence=4 ttl=255 time=1 ms
Reply from 192.168.11.10: bytes=56 Sequence=5 ttl=255 time=57 ms
Reply from 192.168.11.10: bytes=56 Sequence=6 ttl=255 time=3 ms
Reply from 192.168.11.10: bytes=56 Sequence=7 ttl=255 time=4 ms
Reply from 192.168.11.10: bytes=56 Sequence=8 ttl=255 time=4 ms
Reply from 192.168.11.10: bytes=56 Sequence=9 ttl=255 time=3 ms
Reply from 192.168.11.10: bytes=56 Sequence=10 ttl=255 time=3 ms
Reply from 192.168.11.10: bytes=56 Sequence=11 ttl=255 time=3 ms
Reply from 192.168.11.10: bytes=56 Sequence=12 ttl=255 time=2 ms
Reply from 192.168.11.10: bytes=56 Sequence=13 ttl=255 time=2 ms
Reply from 192.168.11.10: bytes=56 Sequence=14 ttl=255 time=1 ms
Reply from 192.168.11.10: bytes=56 Sequence=15 ttl=255 time=1 ms
Reply from 192.168.11.10: bytes=56 Sequence=16 ttl=255 time=1 ms
Reply from 192.168.11.10: bytes=56 Sequence=17 ttl=255 time=1 ms
Reply from 192.168.11.10: bytes=56 Sequence=18 ttl=255 time=1 ms
Reply from 192.168.11.10: bytes=56 Sequence=19 ttl=255 time=1 ms
Reply from 192.168.11.10: bytes=56 Sequence=20 ttl=255 time=1 ms
[rousseau@localhost script]$

如您所见,它跳过了第 3 次 ping(检查了几次)并在第 4 次 ping 总结之前退出。谁能帮忙解决这个问题?提前致谢。

最佳答案

您可能遇到了超时问题。 Expect 的默认超时为 10 秒。 20 次 ping 将花费更多的时间。

在脚本的开头使用以下命令:

设置超时 60

将其设置为 1 分钟。

关于linux - 期望 ping 脚本跳过发送步骤,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14444035/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com