You say you only need the "200 OK" response in a comment.
That allows for solution with some additional advantages over those of
wget -O /dev/null -o /dev/null example.com
. The idea is not to discard the output in some way, but not create any output at all.
That you only need the response means the data that is downloaded into the local file index.html does not need to be downloaded in the first place.
In the HTTP protocol, the command 'GET' is used to download a document. To access a document in a way that does everything except actually downloading the document, there is a special command 'HEAD'.
When using 'GET' for this task, the document is downloaded and discarded locally. Using 'HEAD' does just what you need, it does not transfer the document in the first place. It will allways return the same result code as 'GET' would, by definition.
The syntax to use the method HEAD
with wget
is a little odd: we need to use the option --spider
. In this context, it just does what we want - access the URL with 'HEAD' instead of 'GET'.
We can use the option -q
(quiet) to make wget
not output details about what it does.
Combining that, wget
will neither output anything to stderr, nor save a document.
wget -q --spider 'http://example.com/'
The exit code tells us whether the request was successful or not:
$ wget -q --spider 'http://example.com/'
$ echo $?
0
$ wget -q --spider 'http://example.com/nonexisting'
$ echo $?
8
For a command in crontab
, the fact that there is no output in both cases means you can use getting no output as an indication of errors again.
Your example command would be changed to this:
*/5 * * * * wget -q --spider mysite.com
This has the same advantages as wget -O /dev/null -o /dev/null example.com
. The additional advantage is that the log output, and the document output, are not generated, instead of generated and discarded locally. Or course the big difference is avoiding to download and then discard the document, index.html
.