Crontab helper
cronbeat crontab rewrites the job lines of a crontab so that each one runs through cronbeat run. It is a convenience
for many jobs: you can always edit the crontab by hand instead, see The run command.
cronbeat crontab plan # shows what would change, writes nothingcronbeat crontab apply # backup, write, read back and verifycronbeat crontab undo # restore the backup of the last applyBy default it works on the crontab of the current user (crontab -l and crontab -). Use --file for a file instead:
cronbeat crontab plan --file /etc/cron.d/myapp --cron-dcronbeat crontab apply --file /etc/cron.d/myapp --cron-dSystem crontabs (/etc/crontab and files in /etc/cron.d) have a user column after the schedule. --cron-d makes
the helper understand it and keep it. --cron-d needs --file, and --file on /etc/crontab or /etc/cron.d/...
without --cron-d is refused. The helper does not touch /etc/cron.hourly and the other directories.
An example
Section titled “An example”SHELL=/bin/bashCRON_TZ=Europe/Istanbul
# nightly backup0 2 * * * /opt/backup.sh --full >> /var/log/backup.log 2>&1@daily /usr/local/bin/cleanup.sh@reboot /opt/start.sh30 4 * * * date +%F > /tmp/lastcronbeat crontab plan reports (shortened):
line 5: wrap as "backup" - 0 2 * * * /opt/backup.sh --full >> /var/log/backup.log 2>&1 + 0 2 * * * /usr/local/bin/cronbeat run --name backup --schedule '0 2 * * *' --timezone Europe/Istanbul -- /bin/bash -c '/opt/backup.sh --full >> /var/log/backup.log 2>&1'line 6: wrap as "cleanup"line 7: skip, @reboot has no scheduleline 8: skip, unescaped % (cron turns it into a newline)2 wrapped, 2 skipped, 4 unchanged.- Comments, blank lines and environment lines (
NAME=value) are never touched. - The original command becomes one quoted argument of a shell:
/bin/sh -c '<your command>', or the shell of aSHELL=line above it. Pipes,&&, redirections and quotes behave as before. A single quote inside is escaped. - The schedule is taken from the line.
@dailyand the other macros are converted to five fields (@hourly,@daily,@midnight,@weekly,@monthly,@yearly,@annually). ACRON_TZ=line above sets--timezonefor the jobs below it. Without it, the zone of the server is detected when the job runs, see Time zones. - The job name is the base name of the command without a script extension (
/opt/backup.shbecomesbackup; forpython3 /opt/report.pyit isreport). If two jobs would get the same name, the later one gets a stable suffix made from a hash of its schedule and command. Names used by lines that already runcronbeatare not reused. - The path of
cronbeatis absolute (where the running binary is), because thePATHof cron is short. - Idempotent. A line that already uses
cronbeat runis skipped, so runningapplytwice changes nothing. - The API key is never written into the crontab.
What is skipped
Section titled “What is skipped”Each skipped line stays as it was, with the reason in the plan:
| Line | Why |
|---|---|
@reboot ... |
There is no schedule to monitor. |
A command with an unescaped % |
Cron turns % into a newline and sends the rest as input, quoting cannot repair that. Wrap such a line by hand, or escape the % with a backslash. |
| A line that is not valid | Wrong number of fields or characters that are not part of a cron field. |
A command that starts with - |
It would look like a flag. |
A line that already uses cronbeat |
Already wrapped. |
| A line that would become longer than 1000 bytes | Some cron implementations ignore longer lines. |
Backup and undo
Section titled “Backup and undo”apply saves the current content to ~/.local/state/cronbeat/crontab-backups/ (or $XDG_STATE_HOME/cronbeat/crontab-backups/)
with mode 0600, writes the new content, reads it back and compares it with what it intended to write. A file given with
--file is replaced atomically. It prints the backup file and the exact undo command.
undo restores the backup of the last apply, but only while the crontab is still exactly what apply wrote. If
you or another tool changed it since, undo refuses and cronbeat crontab undo --force restores the backup anyway
(your later changes are lost, so look first).
After applying: the key
Section titled “After applying: the key”The helper wraps the jobs, it cannot give them the key. Make the key available to the user that runs them:
cronbeat configureas that user (writes~/.config/cronbeat/key, or/etc/cronbeat/keyas root), or- a
CRONBEAT_API_KEY=cb_agent_...line near the top of the user’s crontab, or --key-filein the lines you wrap by hand.
For a file in /etc/cron.d with a user other than root, /etc/cronbeat/key (mode 0600, owner root) is not readable
by that user. Run cronbeat configure as that user, or create a key file for it. Files in /etc/cron.d are normally
readable by everyone, so do not put CRONBEAT_API_KEY= in them.
Then check one job by running its wrapped line by hand with --verbose, and look at the Monitors list: the jobs appear
after their first run (CronBeat creates a monitor on the first event of a job). Jobs that you want to appear
immediately can be run once by hand.
Limits of the helper
Section titled “Limits of the helper”- It rewrites lines, it does not understand every dialect of cron. Read the plan before
apply. - The helper is tested with generated crontab files and a fake
crontabcommand, not against every cron implementation. Runplanon your real crontab and keep the backup until you have seen the first runs arrive.

