#!/bin/sh

# Examine one host across the network.

ECHO=echo
SORT=/bin/sort
PING=/usr/etc/ping
TEST=test

rip_flags=
timeout=5
usage="Usage: $0 [-t timeout] fully.qualified.host.name"

# Parse JCL.

while :
do
    case $1 in
    -t) timeout=${2?"$usage"}; rip_flags="$rip_flags $1 $2"; shift;;
    -*) $ECHO $usage 1>&2; exit 1;;
   *.*) target=$1; break;;
     *) $ECHO $usage 1>&2; exit 1;;
    esac
    shift
done

$TEST $# = 1 || { $ECHO $usage 1>&2; exit 1; }

#
# Punt if this host is dead or not reachable.
#
$PING $target $timeout >/dev/null 2>&1 || exit 1;

#
# The remainder of this script is placed between parentheses so we can
# easily eliminate duplicates and perform postprocessing.
#
(
	#
	# If finger fails try systat.
	#
	./finger.rip $rip_flags $target || ./systat.rip $rip_flags $target
	./ftp.rip $rip_flags $target
	#
	# If this host runs Sun (ONC) RPC try NIS and NFS, rusers, etc.
	#
	./rpcinfo.rip $rip_flags $target

) | $SORT -u | ./rip_post
