53

I tried to do a cron and run a url every 5 mintues.

I tried to use WGET however I dont want to download the files on the server, all I want is just to run it.

This is what I used (crontab):

*/5 * * * * wget http://www.example.com/cronit.php

Is there any other command to use other than wget to just run the url and not downlaod it?

kapa
  • 77,694
  • 21
  • 158
  • 175
Abdullah Alsharif
  • 543
  • 1
  • 5
  • 7
  • 1
    Probably too late, but you could use curl, the default operation mode doesn't download, but is not always present on the servers. – Matteo Feb 07 '13 at 15:53
  • Yeah, curl definitely seems like a better solution than using wget. – Matthew G May 11 '13 at 13:39

5 Answers5

108

You could tell wget to not download the contents in a couple of different ways:

wget --spider http://www.example.com/cronit.php

which will just perform a HEAD request but probably do what you want

wget -O /dev/null http://www.example.com/cronit.php

which will save the output to /dev/null (a black hole)

You might want to look at wget's -q switch too which prevents it from creating output

I think that the best option would probably be:

wget -q --spider http://www.example.com/cronit.php

that's unless you have some special logic checking the HTTP method used to request the page

James C
  • 14,047
  • 1
  • 34
  • 43
  • 7
    `wget --quiet --spider --timeout=0 --tries=1 "http://www.example.com/cronit.php"` - this is what I'm using to "ping" a long running php script... *disclaimer* I don't have much experience with `wget` or `crontab` so read the [manual](http://linux.die.net/man/1/wget) and test the solution in your own environment. – Chris Jacob Dec 07 '11 at 00:39
  • I found that if I use the `-q` option, the script (on my server) is not executed, so I leave that out. When I run the script in the terminal, I see output, but does that result in problems when it's run in a cronjob? I guess not, but I may be wrong. – SPRBRN Oct 14 '13 at 07:49
19
wget -O- http://www.example.com/cronit.php >> /dev/null

This means send the file to stdout, and send stdout to /dev/null

Emil Vikström
  • 90,431
  • 16
  • 141
  • 175
5

I tried following format, working fine

*/5 * * * * wget --quiet -O /dev/null http://localhost/cron.php
Mosiur
  • 1,342
  • 13
  • 16
4

If you want get output only when php fail:

*/5 * * * * php -r 'echo file_get_contents(http://www.example.com/cronit.php);'

Or more secure:

*/5 * * * * php /var/www/example/cronit.php

This way you receive an email from cronjob only when the script fails and not whenever the php is called.

angelrove
  • 41
  • 3
1

you can just use this code to hit the script using cron job using cpanel:

wget https://www.example.co.uk/unique-code
Hammad Ahmed khan
  • 1,618
  • 7
  • 19