#!/bin/sh
#
######################################################################
# Isup is a Bourne-shell script designed to use /usr/etc/rpcinfo to  #
# check whether the hosts named in the argument list are up.  Isup   #
# runs ping to each host for 5 seconds; if the host fails to respond #
# isup returns the string "n", while if it responds it returns "y".  # 
######################################################################
#
ourhost=`hostname`
if [ "$#" -eq 0 ]
then
	echo
	echo "You must supply one or more hostnames as arguments to isup."
	echo
	exit
else
	seconds=5
	mustsleep=0
	for arg in $*
	do
		minus=`echo $arg | cut -c1`
		if [ "$minus" = "-" ]
		then
			seconds=`echo $arg | cut -c2-`
		else
			host=$arg
			hosts="$hosts $host"
			if [ "$host" = "$ourhost" -o "$host" = "localhost" ]
			then
				echo "ready and waiting" > /usr/tmp/ISUPOUT$host$$
			else
				/usr/etc/rpcinfo -u $host portmapper 2 > /usr/tmp/ISUPOUT$host$$ 2>&1 &
				mustsleep=1
			fi
			pid="$pid $!"
		fi
	done
	if [ "$pid" = "" ]
	then
		exit
	fi
	if [ $mustsleep -eq 1 ]
	then
		/bin/sleep $seconds
		/bin/kill -KILL $pid >/dev/null 2>&1 
		wait >/dev/null 2>&1
	fi
	for host in $hosts
	do
		up=`grep "ready and waiting" /usr/tmp/ISUPOUT$host$$`
		if [ "$up" != "" ]
		then
			echo "up"
		else
			echo "down"
		fi
		rm /usr/tmp/ISUPOUT$host$$
	done
fi
