#! /bin/sh

# determine the list of all hosts that respond to a ping
#
# (c) Thomas Lange, Institut fuer Informatik, Uni Koeln, 1998,2001

# define a netgroup called allhosts which is the list of all hostnames

fpingopt="-i40"

make_hostlist() {

    # example for a Beowulf cluster
    server=atom00
    nodeprefix=atom
    endnum=25
    # create the list of all hosts
    i=1
    while [ $i -le $endnum ]; do
	num=`printf "%.2d" $i`
	nodes="$nodes $nodeprefix$num"
	i=$(($i+1))
    done
    allhosts="$server $nodes"
}

usage() {
cat <<EOF
   Usage: all_hosts [parameter]

    all_hosts without any option show all answering hosts.

    -h     print this message.
    -n     show all non answering hosts.
    -p     print only the list of all hosts

EOF
exit 0
}

# - - - - - - - - - - - - - - - - - - - -
# if using NIS this is very nice
# prtnetgr prints all hosts belonging to a netgroup
allhosts=`prtnetgr allhosts`
#make_hostlist

while getopts anhp opt
do
        case "$opt" in
	n) fping $fpingopt -u $allhosts 2>/dev/null ;;
        h) usage ;;
        p) echo $allhosts ;;
	*) usage
	    exit 2;;
	esac
done
[ -n "$1" ] || fping $fpingopt -a $allhosts 2>/dev/null
