#!/bin/sh # IsHostAlive.sh # Mon Dec 8 22:41:56 PST 2008 # Chieh Cheng # http://www.CynosureX.com/ # GNU General Public License (GPL) Version 2, June 1991 usage () { scriptName=`basename "$0"` echo " Usage: ${scriptName} host" } if [ $# -eq 1 ] then host="$1" os=`uname -s` case "${os}" in "Darwin") output=`ping -c 1 -t 1 ${host} 2>&1` ;; "Linux") output=`ping -c 1 -W 1 ${host} 2>&1` ;; *) output="Unsupported operating system." echo "${output}" ;; esac result=`echo "${output}" | grep -c " 0% packet loss"` echo ${result} else usage fi