2.11.2. Adding a cron task

Important points:

  • If the task simply specifies the path to the PHP file, it will automatically use PHP settings site in the directory of which it is located, if the path to the PHP interpreter is additionally specified - PHP settings are not used. For example:
    • The task is listed as /home/example/example.com/sub/script.php — script script.php runs with the PHP settings of the sub.example.com site.
    • The task is listed as /usr/local/php72/bin/php /home/example/example.com/sub/script.php — script script.php runs without using the PHP settings of the sub.example.com site.
  • Since cron does not use the PATH variable, you need to specify the full paths to files not only when adding a task, but also in the scripts being launched.
  • If the task is triggered exclusively when the page is opened in a browser, then it should be launched by using wget.
  • The task length must not exceed 255 characters. To run long commands, place them in a Bash script and run it via cron.
  1. Open the section "Task schedule (Cron)".
  2. At the top of the page, click "Add task".
  3. Specify the required settings and click "Save":
    • "Task" - specify the command to be executed according to the schedule. It is recommended to first run it manually, by connecting via SSHto make sure it works exactly as intended.
    • "Simultaneous launch" - select the behavior for the situation when a previously started process does not have time to complete before starting a new one.
    • "Launch time" - specify the time when the task should start. Use one of the ready-made presets or specify your version. Note In the selection and verification of your option will help "Help with setup"which opens our cron calculator, or use third-party services like crontab guru.
    • "Comment" - if necessary, provide an arbitrary comment to the task. Used for convenience. Comments can be useful when there are a lot of added tasks.
    • "Send report on email" — if you want to receive cron task execution reports to the mail, specify the mailbox to which they need to be sent, if the reports are not needed, leave the field blank.
  4. Wait approximately 30-60 minutes for the changes to take effect.

To specify when to start Cron tasks, a specific syntax is used for each value of the specified 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 — launching the task at a time multiple of the specified in X. For example, an indication */20 for seconds and minutes will run the task in the following values: 00, 20, 40.
  • 1,2,3 — enumeration of the required values separated by commas.
  • 1-10 — an indication of the interval of the desired values, in the example all numbers from 1 to 10 will be used.
  • * — any value.

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. Warning! 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 launch of 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 launch, the window displays the contents of the standard output — the text displayed by the command during its execution, or information about errors.
    • "Edit" - changing task settings.
    • "Delete" - deleting a task.
The video shows the old form of adding a task, but the general principles of cron operation have remained unchanged.