LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   Using wget to test if a website is up (https://www.linuxquestions.org/questions/linux-software-2/using-wget-to-test-if-a-website-is-up-676231/)

ericcarlson 10-14-2008 06:31 AM

Using wget to test if a website is up
 
I have a site which every now and again locks up. I know why - the server has too little memory but the upgrade isn't till next year now. When it locks I can log in and "service restart httpd" and alls well for a few more hours/days whatever. What I want is to automate this with a 10 minute cron job, so it would wget http://www.example.com/index.php and if it took more than 30 secs to return then restart the httpd service.

I looked and wget and cant see how to tell from a bash script if it failed because of the timeout. I know most times it will not fail, so I just want it to throw away whatever came back. Anyone got any tips please/a better way to do it? Thanks.

clvic 10-14-2008 08:17 AM

Other than using wget, I'll go a bit off-topic and suggest you to use a software such as monit (http://tildeslash.com/monit/) that is easy to use but at the same time much very flexible and will likely accommodate also future needs.

David1357 10-14-2008 08:23 AM

Quote:

Originally Posted by ericcarlson (Post 3309620)
I looked and wget and cant see how to tell from a bash script if it failed because of the timeout. I know most times it will not fail, so I just want it to throw away whatever came back. Anyone got any tips please/a better way to do it? Thanks.

If you use syntax similar to the following
Code:

[machine:~]:wget --timeout=0.1 --tries=1 http://www.linuxquestions.org/questions/linux-software-2/using-wget-to-test-if-a-website-is-up-676231/
--09:20:57--  http://www.linuxquestions.org/questions/linux-software-2/using-wget-to-test-if-a-website-is-up-676231/
          => `index.html.1'
Resolving www.linuxquestions.org... failed: Connection timed out.
[machine:~]:echo "$?"
1

but change timeout to something reasonable, you can parse the result for the failure reason (i.e. "Connection timed out").

Vit77 10-14-2008 08:36 AM

If you use stand-alone httpd server, may be it would be more reasonable to use nmap for checking if the port alive?


All times are GMT -5. The time now is 08:08 PM.