Script: Server Alive Check Script

About Script: The below script checks whether the given servers in mac_list.sh are alive or not. Send report through email.

*****

#!/bin/sh

HOSTS=`cat ./mac_list.sh`

export TIMESTAMP=`date +%a%d%b%Y-%X%Z`

export LOGOUT=/tmp/asdf.$TIMESTAMP.log

export MAIL_TO=nravi3@gmail.com

echo $HOSTS

for myHost in $HOSTS

do

echo $myHost

ping $myHost -n 3 >/dev/null

if [ $? -eq 0 ]

then

echo “Bingo, Ping is successful for $myHost” >> $LOGOUT

echo “Successful”

else

echo “Oops! Ping failed for $myHost” >> $LOGOUT

echo “Not Successful”

fi

done

mailx -s “Hosts ping is completed.” $MAIL_TO < $LOGOUT

if [ $? -eq 0 ]

then

echo “Email was successfully sent”

else

echo “Email sent is failed”

fi

$ cat mac_list

machine1.us.client.net

machine2.emea.client.net
****

Thanks,
Ravi

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: