An automated script runs
shutdown -r now on a machine, and after a 30s delay, uses ping to determine when the machine is available. I've recently switched the OS from Centos 5 to Oracle Linux 6 and found the behaviour of ping has changed.
I use ping with both a count (-c10), deadline (-w360) and delay (-W1) which should wait up to five minutes for ten successful replies from the machine.
I observe my own machine generating
Destination Host Unreachable messages after 30 seconds that cause
ping to exit after 3 errors ie. well before my desired deadline value. E.g. example exiting after ~37 seconds:
[cs@bst1 ~]# time ping -c10 -w360 -W1 hostother; echo $? PING hostother (10.210.51.155) 56(84) bytes of data. From bst1 (10.210.51.139) icmp_seq=36 Destination Host Unreachable From bst1 (10.210.51.139) icmp_seq=37 Destination Host Unreachable From bst1 (10.210.51.139) icmp_seq=38 Destination Host Unreachable --- hostother ping statistics --- 38 packets transmitted, 0 received, +3 errors, 100% packet loss, time 37008ms pipe 3 real 0m37.010s user 0m0.001s sys 0m0.000s 1
This seems to conflict with
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) Is the behaviour of ping in the face of ICMP errors consistent with the man page? It seems the return code should be 2 under error conditions.
2) Is it possible to prevent my own machine from jumping in with these
Destination Host Unreachable messages?
If I re-run ping a few times, it eventually sees the host and exits cleanly (return code 0).