How to work with cron ? tips and tricks

Modified on Thu, 18 Jan at 11:26 AM

Running PHP script on hosting


/usr/local/bin/php /home/account/domains/example.org/public_html/taskcron.php



Running a script with logging


/usr/local/bin/php /home/account/domains/example.org/public_html/taskcron.php > out.log 2> error.log



Alternative script startup


/usr/bin/wget -O /dev/null http://youdomain/youmegascript.php


Start time parameters


Each record in the schedules file consists of six fields:


  1. Minute

  2. Hour

  3. Day of the month

  4. Month

  5. Day of the week

  6. The string to be run with sh


Minutes and hours should range from 0 to 59 and 0 to 12, respectively, and day of the month and month should range from 1 to 31 and 1 to 12, respectively. The day of the week varies from 0 to 6, where 0 corresponds to Sunday. It can also be denoted as sun, mon, tue, etc. The sixth field is the command or script.


If it is required to run, for example, every 5 minutes, there is no need to make many tasks. It is enough to make one task:

*/5 * * * * * * * /usr/bin/wget -O /dev/null http://youdomain/youmegascript.php


When running scripts, specify the full path to the file



Recommendations when forming an assignment


The correct way to enter the time is with digits and *.

You can use a comma as a separator to set the time. e.g.: 1,2,3 (minutes 1,2 and 3).


To specify a range, you can use a hyphen for example: 5-7 (minutes 5 through 7)

You can also use an asterisk and a slash to specify intervals. e.g.: */2 (every two minutes)


You can combine all of the above methods for flexible customization. for example: 1,5,11-15,30-59/2 (minutes 1, 5, 11 through 15 and every two minutes between 30 and 59 minutes)

No spaces

Was this article helpful?

That’s Great!

Thank you for your feedback

Sorry! We couldn't be helpful

Thank you for your feedback

Let us know how can we improve this article!

Select at least one of the reasons
CAPTCHA verification is required.

Feedback sent

We appreciate your effort and will try to fix the article