Industry guru Dave Taylor offers free tech support on a wide variety of technical and business topics, including HTML, Apple iPhone, online advertising, Cascading Style Sheets, Web design, management, Unix, Linux, search engine optimization, online dating, Mac OS X, shell script programming and Microsoft Windows.

How can my shell script test server status?

i am in big problem so please help on it. below i write the scripts, i don't know it is correct or not, but i want write the shell script for. In particular machine need to check all process are running or not, and we need result to display in the web page like server name = running, not only single server we have so many servers so, result like in the web page:

server1 = running
server2 = not running
server1 = running

like that so many server we have and one more thing is need show in web page with colors and fonts. please help on it!


Dave's Answer:

Since it's apparent that you are at a polytechnic in India (the submission had a ".in" email address suffix) and that you're baffled by what's a fairly rudimentary homework assignment, it would probably be better if I just ignored this question and let you figure it out yourself, but instead I cunningly waited a month or so to get here. That way, it couldn't possibly be helpful to you. :-)

Nonetheless, this really is a straightforward project, so straightforward that I will write up a simple script.

First off, how do you test to see if a server is running? Use the ping command!

For example, let me ping two servers, one I know is running and one I know isn't by virtue of the fact it's an unknown domain:

$ ping -o yahoo.com
PING yahoo.com (206.190.60.37): 56 data bytes
64 bytes from 206.190.60.37: icmp_seq=0 ttl=46 time=69.601 ms

--- yahoo.com ping statistics ---
1 packets transmitted, 1 packets received, 0% packet loss
round-trip min/avg/max/stddev = 69.601/69.601/69.601/0.000 ms
$ echo $?
0
$ ping -o xyz.yahoo.com
ping: cannot resolve xyz.yahoo.com: Unknown host
$ echo $?
68

Really, that should be enough to show you how to proceed, but let's put it in script form:

for server in $(cat serverlist)
do
  ping -o $server > /dev/null 2>&1
  if [ $? -eq 0 ] ; then
    echo "$server = running"
  else
    echo "$server = not running"
  fi
done

Now that should be enough, shouldn't it? The only slight tweak: if the shell script is going to be called directly within a browser (which requires some modifications to the Apache server configuration) then it needs the following as the very first two lines of output generated by the script:

echo "Content-Type: text/html" ; echo ""

Now that should help you quickly gain an "A" in this assignment!



Help others find this article at Del.icio.us, Digg, Netscape, Reddit, and Stumble Upon    

Subscribe!

Never miss another useful Q&A article again! Subscribe to AskDaveTaylor with Google Reader.

Comments

what is the wep key

Posted by: marco at September 21, 2008 7:38 AM

Hey! I'm hosting a game server on my PC is there a way to put on my website if the server is online or offline? Please e-mail me if you know the answer.

Posted by: Sebby05 at October 9, 2008 6:31 AM

I have something to say, now that you mention it, but ...
Starbucks coffee cup I do have a lot to say, and questions of my own for that matter, but first I'd like to say thank you for all your efforts on this Web site by buying you a cup of coffee!

I do have a comment, now that you mention it!











Remember personal info?


Please note that I will never send you any unsolicited email. Ever.

While I'm at it, please note that by submitting a question or comment you're agreeing to my terms of service, which are: you relinquish any subsequent rights of ownership to your material by submitting it on this site.








Ask Dave Taylor: The iPhone App: Advertisement



Follow me on Twitter @DaveTaylor

Search
Find just the answers you seek from among our 2300+ free tech support articles by using our Lijit search engine.


Help!





Subscribe to
Ask Dave Taylor!

Add to Google Reader
Add to My Yahoo!
Subscribe in NewsGator Online

RDF   XML

Free Updates!
Sign up and get free weekly updates and special offers on books, seminars, workshops and more.


Recent Entries
Book Links
© 2002 - 2010 by Dave Taylor. All Rights Reserved.

Note: This web site is for the purpose of disseminating information for educational purposes, free of charge, for the benefit of all visitors. We take great care to provide quality information. However, we do not guarantee, and accept no legal liability whatsoever arising from or connected to, the accuracy, reliability, currency or completeness of any material contained on this web site or on any linked site.

[whiteboard marker tray]
"Ask Dave Taylor®" is a registered trademark of Intuitive Systems, LLC.