2.12.2. Adding a cron task

Important points:

  • cron does not use a variable PATH, so use the full paths to the files not only when adding a task, but also in the scripts they run.
  • To run scripts that only fire when accessed through a browser, use wget.
  • When used in a command symbol $ as a simple character (not a special character) add a backslash in front of it \.
  • Double quotes " are automatically escaped with a backslash \. this does not affect the operation of the command and is not visible in list of added tasks, but it will be visible in the console during the test launch of the task and in the subject of the email with the report when it is launched according to the schedule.
  • The length of the task should not exceed 255 characters. To run long commands, put them in a Bash script and run it via cron.

Automatic command change when saving a task

When the command is given:
  • As an absolute path to the file:
    • With extension .php in one of the catalogs added sites — adds the path to the PHP interpreter of the same version as on the site, and the path to the site’s PHP configuration file. For example, task /home/example/example.com/www/script.php with the added site www.example.com with PHP 8.1 installed it will turn into /usr/local/php81/bin/php -c /home/example/.system/php/www.example.com /home/example/example.com/www/script.php.
    • With extension .py - adds the path to the Python interpreter of the latest available version of the view /usr/bin/python3.10.
    • With extension .sh - add the path to the Bash interpreter /usr/bin/sh.
    • With extension .pl — the path to the Perl interpreter is added /usr/bin/perl.
  • In the form of a URL — a standard command is generated wget ofthekind /usr/bin/wget -O - -q -t 1 'URL'.

In other cases, the command is added in the form in which it was specified.

  1. Open the section «Schedule tasks (cron)».
  2. Click «Add task».
  3. Fill out the form and click «Save»:
    • «Task» — a command to be run according to the schedule. After adding, we recommend running it manually, to make sure it works exactly as intended.
    • «Simultaneous launch» - what to do if the previously launched process does not have time to complete before starting a new one.
    • «Launch time» — task start time. Use one of the ready-made presets or specify your version. Note For your convenience, use our cron calculator (button «Help with setup») or third party services like crontab guru.
    • «Comment» — an arbitrary comment to the task. Used for convenience when many tasks are added.
    • «Send report by email» — mailbox for receiving cron job reports. Leave the field blank if reports are not required.
  4. Wait approximately 30-60 minutes for the changes to take effect.

Cron uses a special syntax to specify the start time. Syntax elements can be combined with each other by separating them with a comma, for example: */30, 1-10, 53 — the task will be launched at: 00, 01 and all numbers up to 10, 30, 53.

  • */X — start the task at a time multiple specified in X. */20 for minutes, it starts at 00, 20 and 40 minutes.
  • 1,2,3 — specific values separated by commas. For clocks, this starts at 1, 2 and 3 o’clock.
  • 1-10 — range of values. For clocks, this is a run every hour from 1 to 10.
  • * — any value. For minutes, this is a run every minute.

All added tasks are displayed in the list:

  • «Launch time» - the task launch schedule in the standard cron format.
  • «Next launch» - date and time of the next scheduled task triggering. Attention! The launch at the specified time may not take place if less than 30-60 minutes have passed since the task was added or changed.
  • «Task» — the full text of the command, a comment to the task and the launch schedule in a human—readable form.
  • «Report» - mail address where they are sent task progress reports, or a dash.
  • «Control» - task control buttons:
    • «Suspend task execution» or «Restore task execution» — stop or resume the launch of a scheduled task.
    • «Test run of the task» — starting the task manually. It can be used to check the operation of a command or launch it ahead of schedule before the scheduled time. After launching, a console window will appear on the page, where the output of the command in the process of work and the result of its execution will be displayed in real time.
    • «Edit» - changing task settings.
    • «Delete» - deleting a task.
Content