Q&A: Can I Configure Cron through UCR Variables?

Question

Can I Configure Cron through UCR Variables?

Answer

You want to run a command at a specific time, let’s say a backup script should be executed daily at 5am.
/root/backup.sh "%Domain Users" to backup all home directories of users belonging to the given group.

Use the following steps to create such an entry for cron.

Step 1

Decide for a name for the task (here: “backup”) and set the command to be used.
Note: In case you need some special characters (like %) they have to be “escaped” by a backslash ("\").

ucr set cron/backup/command="/root/backup.sh \"\%Domain Users\""

Step 2

Add a description for the task for improved readability.
ucr set cron/backup/description="Backup Domain Users"

Step 3

Set the user who should run the command (usually root):
ucr set cron/backup/user=root

Step 4

Define the times when the command has to be started. Syntax is the same as for a default crontab entry. As example:

Minute Hour Day of Month Month Day of Week
3 * */2 1-6 0,6

The above example would be executed at three (3) minutes after every hour (*) on the even days of the month (*/2) in January to June (1-6) when these days are Sunday (0) or Saturday (6).
A matching time would be 7:03am on Sunday, 6th of March. It would not be started on 8:03pm on Monday, 4th of May.

To set the schedule to run on every Monday at 4:30am:
ucr set cron/backup/time="30 4 * * 1"