How to create a periodic task (cron) ? Print

  • 38

You can define periodic tasks that will be executed at a particular time (date, time, ...) or at regular intervals. These are called cron jobs.
Some CMS require you to create cron jobs for their proper functioning, especially to allow them to perform background or maintenance tasks such as archiving, backups, etc...

Important: Be careful when creating cron jobs. If you run them too often, they could degrade the performance of your site.

Here is how to proceed to create a cron job:

Step 1: login and access to the interface

  1. Start by logging into your control panel
  2. ;
  3. Once logged in, scroll down to the "ADVANCED" tab, then click on "Cron Tasks":
    Comment créer une tâche cron
  4. Once in the Cron Tasks

management interface, you can create or modify a cron task, as well as set an email address for notifications.

Step 2 : modify or define the notification email address

Comment créer une tâche cron

Notification e-mail: the address you enter here will receive all output (standard and error) from your script. In other words: everything your script would have displayed "on screen" if you had run it from the command line;

Click the "Update e-mail address" button to save your change.

Step 3: Create a cron job

Comment créer une tâche cron

To create a cron task, you must start by defining its periodicity, which can go from once a year (at a specific date & time) to once a minute.

In the "Common parameters" field you will find predefined examples allowing you to easily configure the most common periodicity. We advise you to use only this menu if you are not yet familiar with the cron syntax.
You can also modify or define your own periodicity parameters, here is a brief description of their meaning:

  • Minute
  • : number of minutes that should elapse between two calls or the minute of each hour that the task should run;
  • Hour
  • : number of hours that should elapse between two calls or the time of day (/24h, at the server's time & time zone) at which the task should be executed;
  • Day
  • : number of days that should elapse between two calls or the day of the month that the task should be executed;
  • Month
  • : number of months that must pass between two calls or the month of the year that the task must be executed;
  • Day

(of the week): This last field allows you to define which day of the week (in the interval from Sunday(0) to Saturday(6) ) the task must be executed.
Command: This is where you enter the command or script to be executed periodically. You should pay special attention to the command or script you call regularly. Some commands like "rm" can be particularly dangerous and destructive towards your website, which can be completely erased if you don't use the correct settings.

Tips and tricks:

  • You can add " >/dev/null 2>&1
  • " (without quotes) at the end of your script to ignore its output and avoid receiving notifications every time it is executed;
  • Some CMS provide you directly the command line to enter in your cron task, you just have to copy and paste what is proposed. To do this, consult the documentation or the specific settings of your CMS.

You can then click on the "Add a new Cron task" button to add your new task whose schedule will take effect immediately: you will see your new cron task appear in the "Current Cron tasks" list.

Step 4 : Edit or delete a cron task

You can then either modify or delete your cron tasks. To do so, in the list of "Current Cron tasks", in the line of the task you want to modify or delete :

  • Click on the "Modify" button to modify the periodicity or the command to be called. Then validate your modification by clicking on the "Modify the line
  • " button;
  • Click on the "Delete" button to delete the task. Then confirm your action by clicking on the "Delete

" button.

Was this answer helpful?