Operating System - HP-UX
1756305 Members
2857 Online
108844 Solutions
New Discussion юеВ

script to check whether the server is alive

 
Joyce Suganthy
Advisor

script to check whether the server is alive

Hi ,

Do any one have any scripts that check whether the server is alive using the ping command?

Regards
Joyce
8 REPLIES 8
Lee Tae-kyung
Regular Advisor

Re: script to check whether the server is alive

It's simple^^

-----------------------------------
while true
do
echo "******************************"
echo " Servers Monitoring "
echo "******************************"
ping Svr1 &
ping Svr2 &
ping Svr3 &
sleep 10
echo " "
done
-------------------------------------

Have a nice day^^

From Korea.
I think I am a specialist in IT Korea^^. I am a programmer and SE and DBA
Mark Grant
Honored Contributor

Re: script to check whether the server is alive

Actually, it's a bit more complicated than that.

You need to give "ping" a timeout. which you do with "ping -n 1". Sadly, the exit status returned by ping is not usable either so you need to check the output to see if the machine was "pingable".

Something like

#!/usr/bin/sh

ping -n 1 | grep "0 packets" && {
echo "Oh dear the machine seems in trouble"
}
Never preceed any demonstration with anything more predictive than "watch this"
Elmar P. Kolkman
Honored Contributor

Re: script to check whether the server is alive

And there is more... A server can respond to ping quite nicely, but that doesn't mean its alive. It only means its network interface is alive.

What we do is first ping the server to see if we can reach it over the network, by pinging with 3 packets and see if at least one got a response. (Some servers are connected over lines that are not up all the time, so it takes time for the network link to work, resulting in some packet loss...)
Then try to auto-login with things like ftp, remsh or ssh, depending on what you have available. And then do some sanity checks on the remote machine, like looking for /sbin/rc commands still running (meaning it is still booting), etc.

I'm afraid that I can't distribute our script, which is highly configurable on the check part, but does it like mentioned above.
Every problem has at least one solution. Only some solutions are harder to find.
Mark Grant
Honored Contributor

Re: script to check whether the server is alive

Elmar,

Sounds like you might benefit for developing that into a client-server architecure. Then simply ask the client if it's OK :)
Never preceed any demonstration with anything more predictive than "watch this"
MarkSyder
Honored Contributor

Re: script to check whether the server is alive

I think Big Brother will meet your requirements.

Sorry, I'm having a busy day and haven't got time to dig out the web address for you, but if you go on to Google and type big brother hp ux you should be pointed in the right direction.

Mark Syder (like the drink but spelt different)
The triumph of evil requires only that good men do nothing
Elmar P. Kolkman
Honored Contributor

Re: script to check whether the server is alive

Mark, problem with client-server is that the server needs to be up to run. Now I can check how much of a server is running. Which is info I need when I run the script.
And now it is in shell scripting, which is easier to maintain for other people (I wrote the script etc. 6 years back, when perl wasn't really an option and we only had 2 people who could read and write C-programs).
Every problem has at least one solution. Only some solutions are harder to find.
Mark Greene_1
Honored Contributor

Re: script to check whether the server is alive

You also first need to ping the gateway for the server running the script. If your system that's doing the checking has been disconnected from the network, everything you check will appear to be down.

mark
the future will be a lot like now, only later
Ross Minkov
Esteemed Contributor

Re: script to check whether the server is alive

http://www.bb4.com

Big Brother monitors System and Network-delivered services for availability. Your current network status is displayed on a color-coded web page in near-real time. When problems are detected, you're immediately notified by e-mail, pager, or text messaging.