#!/bin/bash # How long to sleep between checks. SLEEP_TIME=3 case `uname -s` in Darwin) ONE_PING="-c 1" PING_WAIT="-i 1" ;; Linux) ONE_PING="-c 1" PING_WAIT="-w 1" ;; *) echo "ERROR: Unknown / Unsupported OS. Exiting." exit ;; esac while [ -f hostlist ] do # Clear the file date > pingwatch.tmp echo "--------------------------------------------------------------------------------" >> pingwatch.tmp # fill the file for HOST in `cat hostlist` do ping $ONE_PING $PING_WAIT $HOST > /dev/null 2>&1 STAT=$? if [ $STAT -eq 0 ] then DS="__OK__" else DS="FAILED" fi printf " [%6s] : %-68s\n" $DS $HOST >> pingwatch.tmp done # Clear the screen clear # Dump the file (I use sed because I cannot get spaces in DS variable) sed -e "s/_/ /g" pingwatch.tmp # Wait awhile sleep ${SLEEP_TIME} done