Image

Knowledge base → Task scheduler, scheduled script execution

[Virtual servers] [Shared hosting]
Date of publication: 08.10.2023

Most projects have a need to execute certain scripts on a schedule. Scripts can contain various functions from updating exchange rates to creating a database backup, as well as sending notifications to your clients.

In Linux, the task scheduler is the crond service. To add a task, make sure the script is working by running it in the console and add it to the scheduler using the command:

crontab -e

Where the following sequence must be followed:

Minutes(0-59) Hours(0-23) Days(1-31) Month(1-12) Day of Week(0-7)
    *               *        *            *             *

Here are some examples:

You need to run the script every 5 minutes:

*/5 * * * * /usr/bin/php /var/www/vhosts/domain.tld/httpdocs/cron.php

Execute the script every Monday at 00:00:

0 0 * * 1 /usr/bin/php /var/www/vhosts/domain.tld/httpdocs/cron.php

Execute the script every Sunday at 00:00:

0 0 * * 7 /usr/bin/php /var/www/vhosts/domain.tld/httpdocs/cron.php

Execute the script every day, at 00:00:

0 0 * * * /usr/bin/php /var/www/vhosts/domain.tld/httpdocs/cron.php

Execute script every 12 hours:

0 */12 * * * /usr/bin/php /var/www/vhosts/domain.tld/httpdocs/cron.php

Note that in order to save changes on exit, the new last date in the editor crontab -e must be empty.





No Comments Yet