Apr 12, 2007

SCRIPT TO MONITOR A SERVER IN EVERY 30 MINUTES

This script is used to check the health of Your servers.
# !/bin/bash
# add ip / hostname separated by while space 
HOSTS="aaa.com bbb.com 202.10.193.46 router"
# no ping request
COUNT=1
# email report when 
SUBJECT="Ping failed Server Seems to be DOWN"
EMAILID="Your emailid"
for myHost in $HOSTS
do
count=$(ping -c $COUNT $myHost | grep 'received' | awk -F',' '{ print $2 }' | awk '{ print $1 }')
if [ $count -eq 0 ]; then
# 100% failed 
echo "Host : $myHost is down (ping failed) at $(date)" | mail -s "$SUBJECT" $EMAILID

No comments: