Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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, But not sure how this works. Can someone please explain. It will be helpful for me.

share|improve this question
up vote 3 down vote accepted

wget is an HTTP client, so you're making a web request to 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:


wget -O /dev/null -q

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

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.


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

curl -sL -w "%{http_code}" -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


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.