Databases
cancel
Showing results for 
Search instead for 
Did you mean: 

Automatic checking servers to see if alive

SOLVED
Go to solution
Marty Metras
Super Advisor

Automatic checking servers to see if alive

I want to writ a script in UNIX and Linux that will check my servers to see if they are alive and email/page me if not.
I use ping manaully. I know there must be another command that will do something like ping and return a message that I could grep the output to see if the box is alive.
I want to put this scrip on 2-3 boxes so if one goes down I'll be alerted of the problem.
So what or my options? What are the other commands that I could look into?

Marty
The only thing that always remain the same are the changes.
8 REPLIES
Andreas D. Skjervold
Honored Contributor

Re: Automatic checking servers to see if alive

Hi

Check out the Big Brother software.
http://bb4.com/

Its free for non comercial use.

Andreas
Only by ignoring what everyone think is important, can you be aware of what everyone ignores!
Robin Wakefield
Honored Contributor

Re: Automatic checking servers to see if alive

Hi Marty,

You could still use ping within a script:

for HOST in "list of hosts" ; do
/etc/ping $HOST 8 1 | grep -q 100%
if [ $? -eq 0 ]; then
mailx -s "Host $HOST down" yourname
fi
done

Rgds, Robin.
Peter Kloetgen
Esteemed Contributor

Re: Automatic checking servers to see if alive

Hi Marty,

you have to redirect the output of your ping- command into a file, then grep into the file for error messages you want to be informed about. This should be simple. If a error message is found, grep has a return code of 0.

check this:

if test $? -eq 0
then
mail root@computer << EOF
Write_the_mail_notification_that_you_need
EOF
fi

Allways stay on the bright side of life!

Peter
I'm learning here as well as helping
Bill McNAMARA_1
Honored Contributor
Solution

Re: Automatic checking servers to see if alive

Start with a ping

kibo:root> ./script
PING rio: 64 byte packets
64 bytes from 15.128.171.132: icmp_seq=0. time=0. ms

----rio PING Statistics----
1 packets transmitted, 1 packets received, 0% packet loss
round-trip (ms) min/avg/max = 0/0/0
Pang rio : return 0
PING kibo: 64 byte packets
64 bytes from 15.128.171.159: icmp_seq=0. time=0. ms

----kibo PING Statistics----
1 packets transmitted, 1 packets received, 0% packet loss
round-trip (ms) min/avg/max = 0/0/0
Pang kibo : return 0
PING manaus.grenoble.hp.com: 64 byte packets
64 bytes from 15.128.171.118: icmp_seq=0. time=0. ms

----manaus.grenoble.hp.com PING Statistics----
1 packets transmitted, 1 packets received, 0% packet loss
round-trip (ms) min/avg/max = 0/0/0
Pang manaus : return 0
PING pereal: 64 byte packets
64 bytes from 15.128.171.145: icmp_seq=0. time=0. ms

----pereal PING Statistics----
1 packets transmitted, 1 packets received, 0% packet loss
round-trip (ms) min/avg/max = 0/0/0
Pang pereal : return 0
PING mickey.grenoble.hp.com: 64 byte packets
64 bytes from 15.128.132.22: icmp_seq=0. time=0. ms

----mickey.grenoble.hp.com PING Statistics----
1 packets transmitted, 1 packets received, 0% packet loss
round-trip (ms) min/avg/max = 0/0/0
Pang mickey : return 0
ping: unknown host lkfsdajf
Pang lkfsdajf : return 1



---------------
/tmp/servers

rio
kibo
manaus
pereal
mickey
lkfsdajf



-----------------
script

for i in $(cat /tmp/servers)
do
ping $i -n 1
rtn=$?
echo "Pang $i : return $rtn"

if [[ rtn != "0" ]] ; then
echo "$i : down at $(date)" > /tmp/mailmsg
#insert mail command here
else
echo "$i : up at $(date)"
fi
done


It works for me (tm)
Bill McNAMARA_1
Honored Contributor

Re: Automatic checking servers to see if alive

The mail command:

cat /tmp/message| mailx user

It works for me (tm)
Krishna Prasad
Trusted Contributor

Re: Automatic checking servers to see if alive

The ping command will work but here is an idea where you wan't have to create a file.

If you remsh setup between the boxes try this.

remsh "remote_hostname" hostname | grep hostname > /dev/null

if [ $? = 1 ]
then
echo "remote_hostname not responding" | sendmail or mailx command to deliver message
fi
Positive Results requires Positive Thinking
Krishna Prasad
Trusted Contributor

Re: Automatic checking servers to see if alive

That | grep should be

remsh "remote_hostname" hostname | grep "remote_hostname"

sorry.
Positive Results requires Positive Thinking
Marty Metras
Super Advisor

Re: Automatic checking servers to see if alive

Thanks for all your help.
From what I got from all of you I have already writen the script I need.
Marty
The only thing that always remain the same are the changes.