I think there's a bug in ping - netkit-base-0.10-31; RedHat 6.0: When I send a single ping to a machine that's shut down, ping keeps on trying after the first failure, despite using -c 1 . That means it's impossible to test whether a machine is alive, eg ping -c 1 datix if [ $? -eq 0 ]; then echo "It's alive" else echo "No ping response" fi because ping *never* returns! Ping reports "Destination Host Unreachable" over and over... ping -c 1 somemachine works as expected if "somemachine" responds (returns 0) or "somemachine" doesn't exist (returns 1) but if "somemachine" exists but is turned off, ping tries forever. Ping(1) clearly states: If ping does not receive any reply packets at all it will exit with code 1. On 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. I've written a little script to work around this bug, but I'm not happy having to do so. Can ping be fixed to agree with its man page? ************** /usr/local/bin/pingtest ************* #!/bin/sh # Silently pings $1 to see if it's alive, # with protection against hangs if it's not (ping has a bug) # Returns 0 if alive; else 1 nohup ping -c1 $1 > /dev/null 2>&1 & sleep 2 PINGPID=` ps | grep "ping " | grep -v grep | cut -d " " -f1 ` if [ -n "$PINGPID" ]; then # echo "ping $1 is hung; kill $PINGPID" kill $PINGPID exit 1 else # echo ping $1 succeeded exit 0 fi ************** END /usr/local/bin/pingtest ************* This must be a bug.
This problem should be fixed in the latest rawhide version of netkit-base available at: ftp://ftp.redhat.com/rawhide/i386/RedHat/RPMS/netkit-base-0.10-36.i386.rpm Please try this one and reopen this bug if the problem continues. This fix will also be in the next release. ------- Additional Comments From 09/30/99 17:23 ------- This bug appears to have resurfaced in netkit-base-0.10-37.
Other recent problems with ping were solved by redhat replacing the ping they were using with the one from iputils-990610. This ping has a -w option which is broken which could have been used to circumvent the timeout problem. If you take the ping from iputils-991024 this now works properly. i.e. w/ 991024 "ping -w 10 -c 1 deadhost" will return for both a host on the local network and hosts on remote networks. I was going to upload an rpm to contrib.redhat.com but apparently I'm not allowed. Is there a special site/directory for uploads?