1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
|
#! /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
|