Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

will this cronjob work?

Tags:

php

cron

im trying to set up a cronjob to run a PHP file. i just want to know if i am doing it right or not.

lets say the php is located at http://mysite.com/myscript/cronjob.php, and i want it to run every 3 hours.

i am very new to cronjobs so i apologise if it seems like i have no clue what i am doing.

Minute  Hour    Day     Month   Weekday     Command

*   */3     *   *   *   http://mysite.com/myscript/cronjob.php

i want this to run that PHP script every 3 hours. will this work or do i have to use a different command?

like image 913
scarhand Avatar asked Oct 11 '11 01:10

scarhand


People also ask

How do I know if a cron job is working?

Running the “systemctl” command along with the status flag will check the status of the Cron service as shown in the image below. If the status is “Active (Running)” then it will be confirmed that crontab is working perfectly well, otherwise not.

What is the use of * * * * * In cron?

It is a wildcard for every part of the cron schedule expression. So * * * * * means every minute of every hour of every day of every month and every day of the week .

How do I know if my cron job is failing?

Check that your cron job is running by finding the attempted execution in syslog. When cron attempts to run a command, it logs it in syslog. By grepping syslog for the name of the command you found in a crontab file you can validate that your job is scheduled correctly and cron is running.

How do cron jobs work?

Cron Jobs allow you to automate specific commands or scripts on your server to complete repetitive tasks automatically. This can be a very resourceful tool as a Cron Job can be set to run by 15 minute or hourly increments, a day of the week or month, or any combination of these.


2 Answers

No, this won't work. A URL is not an executable, it is simply a URL.

You could put wget http://mysite.com/myscript/cronjob.php for your command, but is that really what you want?

The best way (if the script is on the local server) is to call PHP directly:

php /var/www/myscript/cronjob.php

like image 189
Brad Avatar answered Oct 21 '22 06:10

Brad


Almost, this should do it

* */3 * * * wget -q -o /dev/null http://mysite.com/myscript/cronjob.php

or with curl

* */3 * * * curl -s -o /dev/null http://mysite.com/myscript/cronjob.php

the -s / -q will silent the output and the -o will redirect the scripts output into /dev/null

like image 38
Ryan Gibbons Avatar answered Oct 21 '22 07:10

Ryan Gibbons