#!/bin/sh
#
# Return a list of hosts which not reachable via ICMP echo
#
# Jim Trocki, trockij@transmeta.com
#
# $Id: fping.monitor,v 1.9 1999/02/16 12:28:58 trockij Exp $
#
#    Copyright (C) 1998, Jim Trocki
#
#    This program is free software; you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation; either version 2 of the License, or
#    (at your option) any later version.
#
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with this program; if not, write to the Free Software
#    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
#
p=`which fping`
if [ ! -x "$p" ]
then
    echo fping.monitor error, could not find fping
    exit 1
fi

case "$1" in
    -*) CMD="fping -u $*"
	;;
    *) CMD="fping -u -r 3 -t 2000 $*"
	;;
esac

a=`$CMD`
retval=$?

if [ "$retval" = 1 ]
then
    echo "$a" | tr ' ' '\n'  | sort | tr '\n' ' '
    echo
    exit $retval
fi

if [ "$retval" = 2 ]
then
    echo fping: no hosts found
    exit 1
fi

if [ "$retval" = 3 ]
then
    echo fping: invalid command line arguments
    exit 1
fi

if [ "$retval" = 4 ]
then
    echo fping: system call failure
    exit 1
fi
