Script to tell me what hosts are down in a list

#! /usr/bin/ksh
#################################################################
# Title      :  pinghosts - Returns status of all hosts
# Author     :  John Rigler
# Date       :  01-09-2009
# Requires   :  ksh
#################################################################



grep -v "^#" $1 | while read HOSTNAME # Only read uncommented lines
  do
    # Execute the ping once and wait 2 seconds
    ping -c 1 -w 2 $HOSTNAME  2>&1 1>/dev/null
    if [[ ! $? -eq 0 ]]
    then
        echo "$HOSTNAME down"
    fi
  done

Leave a Reply

Your email address will not be published. Required fields are marked *