Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I would like to write a script to check whethere the application is up or not using unix shell scripts.

From googling I found a script wget -O /dev/null -q http://mysite.com, But not sure how this works. Can someone please explain. It will be helpful for me.

share|improve this question

1 Answer 1

up vote 3 down vote accepted

wget is an HTTP client, so you're making a web request to http://mysite.com. You'll have to check the exit status of the wget command: if the request is successful, the exit status will be "0", and otherwise if it's not successful.

So, your check script may look something like:

#!/bin/bash

wget -O /dev/null -q http://mysite.com

if [ "$?" -ne "0" ]; then
  echo "Web site is down!"
fi

If you're not really sure about shell scripting, it might be better to use a service that will perform the check, along the lines of Pingdom.

Update:

Instead of using wget, it may be better to use curl. Something like this:

curl -sL -w "%{http_code}" http://mysite.com -o /dev/null

This will return the HTTP response code, so you can do more obvious controlled comparisons (i.e., curl will return 404, whereas wget will return some non-zero exit code that you have to figure out from documentation)

share|improve this answer
    
Thanks a lot cjc !!!, One more doubt how long it will wait for the response before exit? any idea?? –  Selvakumar P Feb 15 '12 at 12:37
    
wget's timeout is by default 900 seconds. You can change this to something else with the --timeout=seconds option. What you should set this for depends on your website, how long you think a reasonable response to take, etc. Look at man wget for all the options. –  cjc Feb 15 '12 at 12:43
    
Thank you very much!!! –  Selvakumar P Feb 15 '12 at 12:54

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.