I have 2 servers. One of them often crashes. I want to send a SMS to my phone when it crashes.

I wrote this simple bash script in another server and put it in crontab to run every 10 minutes.

wget --spider http://mywebsite.com || php sendsms.php

Is this the right way? Sometimes I get SMS, but I see that server is running without any problem.

  • Is the --spider really necessary? If the site is large, it could take a long time, and if the first page works, you already know Apache is working. Are there particular pages (perhaps CGI scripts) which may malfunction for other reasons? Then maybe use (one of) those as your test case.
    – tripleee
    Jun 23, 2013 at 6:22

1 Answer 1


You should be able to see from the output of wget --spider ... why wget has failed. That information is emailed to the user running the script or, if you use

[email protected]

you can redirect it to your email account for review.

If there are spurious network or DNS errors you can do a double check to see if unavailability was temporary, and thereby reducing the number of false positives:

wget --spider -a /var/tmp/wget_test.log http://mywebsite.com || (sleep 10; wget --spider http://mywebsite.com ) || php sendsms.php

Note that I have made the first try, append output to a log file (instead of printing to stderr). This way you don't get an email every 10 minutes if things run fine.

Every wget run first prints a date-timestamp and url when it tries that url. You will be able to review all runs that fail the first wget and pass the second by matching the date-timestamp from the emailed output of the second wget to that from the log file.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .