:
# The PING command and the method to test the result 
# must be individualized for each platform.
# If you have this file, we are not sure how the ping works on your
# particular platform.  There are two main styles:
# 1) Lachman TCP/IP and pure BSD (SCO Unix, DEC Alpha)
#    ping [-Rdfnqrv] [-c count] [-i wait] [-l preload]  [-p pattern]
#           [-s packetsize] host
#
# 2) The other style is on SUN OS, Solaris, SVR4
#      ping host [timeout]
#          or
#      ping -s[drvRl] host [data size] [n packets]
# 
# The importance here is that some pings will hang if the host is 
# unavailable and the right command is not given.
# Here we try to figure out which you have:
[ $# -eq 0 ] && exit 1
TMP1=/tmp/cttest_$$
STATUS=0
PING=ping
[ -x /sbin/ping ] && PING=/sbin/ping 
[ -x /usr/sbin/ping ] && PING=/usr/sbin/ping
[ -x /etc/ping ] && PING=/etc/ping                   # For HP UX
$PING -? 2> $TMP1

uname -r | grep -q '\.el7\.'
ISEL7=$?
grep -q timeout $TMP1
HASTIMEOUT=$?

if [ $HASTIMEOUT -eq 0 ] && [ $ISEL7 -ne 0 ]
then
	# SUN OS, Solaris, SVR4 style
	$PING $* 2 > $TMP1 2>&1
	[ $? -eq 1 ] && STATUS=1
else
	# Lachman, SCO, DEC Alpha style, BSD, Linux
	OPTS=""
	SYSNAME=`uname`
	case "$SYSNAME" in
		[Ll]inux) OPTS="-w 5";;
	esac
	$PING -qc 1 $OPTS $* > $TMP1 2>&1
	[ $? -eq 1 ] && STATUS=1
	if egrep "0 packets received|unknown" $TMP1 >/dev/null 2>&1
	then
		STATUS=1
	fi
fi
rm -f $TMP1
exit $STATUS
