1830735 Members
1842 Online
110015 Solutions
New Discussion

ping server

 
SOLVED
Go to solution
maxpayne
Occasional Contributor

ping server

Hi,

I have 5 servers. I need a script that can ping to all the 5 server and if it failed to respond, an sms alert will be sent to me.

Thank you.
6 REPLIES 6
Raj D.
Honored Contributor
Solution

Re: ping server

Hi Md Farijalhumum bin Raml,

Here is the script for pingcheck,

########################################
RESULT=`ping server1 -n 3 | grep transmitted | awk '{print $7}'`

if [ $RESULT = "0%" ]
then
tput bold ; echo " server1 is ALIVE " ; tput rmso
else
echo " server1 is NOT REACHABLE !!!! "
fi
########################################

* You can add multiple server entry by calling through a server list file.


Cheers,
Raj
" If u think u can , If u think u cannot , - You are always Right . "
Raj D.
Honored Contributor

Re: ping server

Hi maxpayne,

Here is the full script that will help to check the all servers for ping,

You need :
1) server.list [ server names file ]
2) pingcheck.sh [ The below script ]
------------------


####################################
# Script pingcheck.sh
# Ver 1.01 (Raj.D)
# Check all servers if alive or down.
#####################################
for i in `cat server.list`
do
echo $i

RESULT=`ping $i -n 2 | grep transmitted | awk '{print $7}'`

if [ $RESULT = "0%" ]
then
tput bold ; echo "$i is ALIVE " ; tput rmso
else


tput smso ; echo "$i is NOT REACHABLE !!!! " ; tput rmso
fi
done
##########################################


Cheers,
Raj.
" If u think u can , If u think u cannot , - You are always Right . "
Raj D.
Honored Contributor

Re: ping server

The above script assumes there is no network issues , hence that will give 0% packet loss( For Alive cae) and 100% packet loss ( for not reachable case).

HTH,
Raj.
" If u think u can , If u think u cannot , - You are always Right . "
maxpayne
Occasional Contributor

Re: ping server

Hi Raj,

Great script. How can I send an sms alert if the server is not reachable.
Raj D.
Honored Contributor

Re: ping server

Hi Maxpayne,

You need to add the mailx command after else statement and before fi.

ex:

echo " $i is unreachable" | mailx -s "$i is unreachable" yourcell@domain.com


cheers,
Raj.


" If u think u can , If u think u cannot , - You are always Right . "
Raj D.
Honored Contributor

Re: ping server

Also , Dont forget to assign points to all of your threads,

Thank you.
" If u think u can , If u think u cannot , - You are always Right . "