89

I'm newbie in cron commands and I need help.

I have a script on http://example.com/check/.

Whats is command for cron to run this URL every 5 minutes?

I tried

*/5 * * * * /home/test/check.php

But I want to run URL not relative script address. How to do it?

nbro
  • 15,395
  • 32
  • 113
  • 196
Mirgorod
  • 31,413
  • 18
  • 51
  • 63

9 Answers9

139

Based on the comments try

*/5 * * * * wget http://example.com/check

[Edit: 10 Apr 2017]

This answer still seems to be getting a few hits so I thought I'd add a link to a new page I stumbled across which may help create cron commands: https://crontab.guru

DilbertDave
  • 3,406
  • 3
  • 33
  • 42
  • 9
    wget will create temporary files uses like that – Matteo Apr 09 '14 at 17:22
  • 9
    Edited to ensure temporary file not created (hope it's accepted, but JiC) `*/5 * * * * wget -qO- http://example.com/check &> /dev/null` – MrMesees Oct 02 '16 at 13:10
  • 3
    I would do */5 * * * * wget http://example.com/check --delete-after to make sure there are no temporary files – NicoJuicy Oct 13 '16 at 09:46
  • And don't forget to call `sudo service cron reload` after saving the *crontab file* ;) – eapo Dec 16 '20 at 05:02
128

Use cURL:

*/5 * * * * curl http://example.com/check/
Yan Berk
  • 14,328
  • 9
  • 55
  • 52
  • 20
    Just a note, you should run curl without output or progress by piping to /dev/null like so. `*/5 * * * * curl -s http://example.com/check/ > /dev/null` – MrMesees Oct 02 '16 at 13:20
  • If any error occured on that, you could try double quotes around URL. like that curl -s "http://example.com/check/" > /dev/null – Kiriakos Grhgoriadhs Feb 04 '21 at 11:12
50

The other advantage of using curl is that you also can keep the HTTP way of sending parameters to your script if you need to, by using $_GET, $_POST etc like this:

*/5 * * * * curl --request GET 'http://exemple.com/path/check.php?param1=1&param2=2'
Tom Fenech
  • 72,334
  • 12
  • 107
  • 141
Arnaud Bouchot
  • 1,885
  • 1
  • 21
  • 19
10

Here is an example of the wget script in action:

wget -q -O /dev/null "http://example.com/cronjob.php" > /dev/null 2>&1

Using -O parameter like the above means that the output of the web request will be sent to STDOUT (standard output).

And the >/dev/null 2>&1 will instruct standard output to be redirected to a black hole. So no message from the executing program is returned to the screen.

William Prigol Lopes
  • 1,803
  • 14
  • 31
5zellsb
  • 181
  • 2
  • 7
3

To run a url, you need a program to get that url. You can try wget or curl. See manuals for available options.

Charles Brunet
  • 21,797
  • 24
  • 83
  • 124
3

To run a URL simply use command below easy yess CPanel 100%

/usr/bin/php -q /home/CpanelUsername/public_html/RootFolder/cronjob/fetch.php

I hope this help.

sajad abbasi
  • 1,988
  • 2
  • 22
  • 43
3

Nothing worked for me on my linux hosting. The only possible commands they provide are:

/usr/local/bin/php absolute/path/to/cron/script

and

/usr/local/bin/ea-php56 absolute/domain_path/path/to/cron/script 

This is how I made it to work: 1. I created simple test.php file with the following content:

echo file_get_contents('http://example.com/check/');

2. I set the cronjob with the option server gived me using absolute inner path :)

/usr/local/bin/php absolute/path/to/public_html/test.php
Atanas Atanasov
  • 203
  • 1
  • 4
2

Use perfect URL:

*/5 * * * * wget -q -O /dev/null "https://www.example.com/payment/WebhookOrderCron" > /dev/null 2>&1
Toni
  • 1,555
  • 4
  • 15
  • 23
1

I try GET 'http://example.com/?var=value' Important use ' add >/dev/null 2>&1 for not send email when this activate Sorry for my English

Jorhel Reyes
  • 113
  • 1
  • 8