+test_ping() +{
- ping -c 1 -W 1 $LKP_SERVER > /dev/null || return 1
This looks not necessary:
|| return 1
-w seems somehow better than -W, since the man page explicitly discussed it:
If ping does not receive any reply packets at all it will exit with code 1. If a packet count and deadline are both specified, and fewer than count packets are received by the time the deadline has arrived, it will also exit with code 1. On other error it exits with code 2. Otherwise it exits with code 0.
=> This makes it possible to use the exit code to see if a host is => alive or not.
1. Nice, i'll delete 'return 1'.
2. about -w and -W. -w <deadline> reply wait <deadline> in seconds -W <timeout> time to wait for response
here is my test result: -w deadline: is the time limit for the ping cmd, not for one ping response. -W timeout: is the timeout for each response.
yuchuan@crystal ~/todo/deploy/YuChuan/daily% ping -w 3 baidu.com PING baidu.com (220.181.38.148) 56(84) bytes of data. 64 bytes from 220.181.38.148 (220.181.38.148): icmp_seq=1 ttl=50 time=33.7 ms 64 bytes from 220.181.38.148 (220.181.38.148): icmp_seq=2 ttl=50 time=32.6 ms 64 bytes from 220.181.38.148 (220.181.38.148): icmp_seq=3 ttl=50 time=32.4 ms
--- baidu.com ping statistics --- 3 packets transmitted, 3 received, 0% packet loss, time 2003ms rtt min/avg/max/mdev = 32.407/32.892/33.652/0.543 ms yuchuan@crystal ~/todo/deploy/YuChuan/daily% ping -W 3 baidu.com PING baidu.com (39.156.69.79) 56(84) bytes of data. 64 bytes from 39.156.69.79 (39.156.69.79): icmp_seq=1 ttl=49 time=30.5 ms 64 bytes from 39.156.69.79 (39.156.69.79): icmp_seq=2 ttl=49 time=39.4 ms 64 bytes from 39.156.69.79 (39.156.69.79): icmp_seq=3 ttl=49 time=29.7 ms 64 bytes from 39.156.69.79 (39.156.69.79): icmp_seq=4 ttl=49 time=29.7 ms 64 bytes from 39.156.69.79 (39.156.69.79): icmp_seq=5 ttl=49 time=35.2 ms 64 bytes from 39.156.69.79 (39.156.69.79): icmp_seq=6 ttl=49 time=29.9 ms 64 bytes from 39.156.69.79 (39.156.69.79): icmp_seq=7 ttl=49 time=29.7 ms 64 bytes from 39.156.69.79 (39.156.69.79): icmp_seq=8 ttl=49 time=37.3 ms ^C --- baidu.com ping statistics --- 8 packets transmitted, 8 received, 0% packet loss, time 7010ms rtt min/avg/max/mdev = 29.659/32.678/39.436/3.756 ms
So in the code, we need test whether only one ping is ok, '-w' looks more appropriate?
-------- Thanks Yu Chuan
Thanks, Fengguang
+}
network_ok() { local i for i in /sys/class/net/*/ do [ "${i#*/lo/}" != "$i" ] && continue
[ "$(cat $i/operstate)" = 'up' ] && return 0
[ "$(cat $i/carrier 2>/dev/null)" = '1' ] && return 0
[ "$(cat $i/operstate)" = 'up' ] && test_ping && return 0
[ "$(cat $i/carrier 2>/dev/null)" = '1' ] && test_ping && return 0
done
is_clearlinux && {
-- 2.23.0