Permalink
Switch branches/tags
Nothing to show
Find file
Fetching contributors…
Cannot retrieve contributors at this time
executable file 42 lines (33 sloc) 678 Bytes
#!/bin/bash
PING_COUNT=10
me=`basename $0`
usage () {
cat <<EOF >&2
Usage: $me HOSTNAME
EOF
exit 1
}
if [ "$1" == '-h' ] || [ "$1" == '--help' ] || [ $# != 1 ]; then
usage
fi
host="$1"
shift
host_up=
case "$OSTYPE" in
solaris*)
echo "FIXME: ping count option?" >&2
exit 1
# redirect stderr to avoid "no route to host" type errors
ping -s "$host" 2>&1 | grep -q 'bytes from' && host_up=yes
;;
# FreeBSD and Linux
*)
ping -c "$PING_COUNT" -w "$PING_COUNT" "$host" 2>&1 | \
grep -q 'bytes from' && host_up=yes
;;
esac
if [ -n "$host_up" ]; then
exit 0
else
exit 1
fi