Monday, November 28, 2011

Script to Alert when server is UP and running

The inspiration which led me to making this script was because of a couple of reasons. Firstly because the internet connectivity is intermittent here, so i run this script and check for google.com hence I will get notified when connection is back unless google is down ;) .

The second reason is that I work on a lot of servers and when a server is gone for a reboot, I can run this script and give the server IP as input hence I will get notified when server is back online.

++++++++++++++++++++++++++++++++++++++
#!/bin/bash
echo "Enter ip/domain name"
read a
HOSTS=$a
COUNT=4
for myHost in $HOSTS
do
count=$(ping -c $COUNT $myHost | grep 'received' | awk -F',' '{ print $2 }' | awk '{ print $1 }')
if [ $count -eq 4 ]; then
# 100% Up
echo "Host : $myHost is Working (ping Sucess) at $(date)"
fi
done
++++++++++++++++++++++++++++++++++++++

0 comments:

Post a Comment

Twitter Delicious Facebook Digg Stumbleupon Favorites More

 
Design by Free WordPress Themes | Bloggerized by Lasantha - Premium Blogger Themes | Affiliate Network Reviews