The run command
cronbeat run starts your command, passes everything through and reports the run to CronBeat. This page lists what it
does exactly. For the first setup see Overview and install.
cronbeat run --name JOB [--schedule "CRON"] [--timezone IANA] [--grace 5m|300] [--max-runtime 1h|3600] [--output failure|always|never] [--tail-bytes N] [--api-url URL] [--key-file FILE] [--verbose] -- COMMAND [ARGS...]Everything after -- belongs to your command, including words that look like flags. Without -- the command starts at
the first word that is not a flag of cronbeat. To run a pipeline, a redirection or &&, give the command to a shell:
cronbeat run --name db-dump --schedule "30 1 * * *" -- /bin/sh -c 'pg_dump mydb | gzip > /backup/mydb.sql.gz'| Flag | Meaning |
|---|---|
--name |
The job name: 1 to 64 characters, letters, digits, ., _, -. Required to monitor the job. It identifies the monitor, so two different jobs need two names. |
--schedule |
The cron schedule of the job: five fields (0 2 * * *) or a macro (@hourly, @daily, @midnight, @weekly, @monthly, @yearly, @annually; macros are converted to five fields). Required the first time a job is reported, because CronBeat creates the monitor from it. @reboot has no schedule and cannot be used. |
--timezone |
IANA time zone of the schedule, for example Europe/Istanbul. If you leave it out, the zone of the server is detected, see Time zones. |
--grace |
Grace period of the monitor: seconds (300) or a duration (5m, 1h30m). Used only when the monitor is created. Default 300 seconds. Allowed: up to 7 days. |
--max-runtime |
Maximum runtime: seconds or a duration. Used only when the monitor is created. Allowed: 1 second to 24 hours. |
--output |
When the output tail is sent: failure (default), always or never, see Output. |
--tail-bytes |
Size of the output tail: 1 to 8192 bytes, default 4096. |
--api-url |
The CronBeat API address. Default https://api.cronbeat.dev, or CRONBEAT_API_URL. It must be https (plain http only for localhost, 127.0.0.1 and ::1). |
--key-file |
Read the API key from this file instead of the default places. |
--verbose |
Print what cronbeat does (never the key) and show every warning instead of at most one per 6 hours. |
A value outside these limits is ignored with a warning, except --grace over 7 days and --max-runtime over 24 hours:
the CLI sends them and CronBeat refuses the report (HTTP 400), so that run is not reported. Keep them in range.
If the flags of cronbeat itself are wrong but a command is given after --, the command still runs, without
monitoring, after a warning. Only a missing command is a usage error.
Environment variables
Section titled “Environment variables”| Variable | Meaning |
|---|---|
CRONBEAT_API_KEY |
The API key of the host agent. Highest priority. |
CRONBEAT_KEY_FILE |
Path of a key file. Same as --key-file. |
CRONBEAT_API_URL |
The API address, default https://api.cronbeat.dev. |
TZ |
Used to detect the time zone when --timezone is absent. |
XDG_CACHE_HOME |
Where the warning state is kept ($XDG_CACHE_HOME/cronbeat/warned.json, default ~/.cache/cronbeat/warned.json). |
XDG_STATE_HOME |
Where the crontab helper keeps backups (default ~/.local/state). |
Your job does not see the API key. cronbeat run removes CRONBEAT_API_KEY from the environment of the command it
starts, so a script, and the programs it starts, cannot read or leak it.
The API key
Section titled “The API key”The key is never an argument (it would show in ps). cronbeat looks for it in this order and uses the first one that
exists:
- the environment variable
CRONBEAT_API_KEY, - the file named by
--key-fileorCRONBEAT_KEY_FILE, /etc/cronbeat/key,~/.config/cronbeat/key.
If you name a source explicitly (--key-file, CRONBEAT_KEY_FILE) and it fails, cronbeat does not fall back to
another key. Key files must be a regular file with mode 0600 (or stricter): a file readable by group or others is
refused with a message like key file ... has mode 0644, expected 0600. A key file holds the key on its first line.
cronbeat configure writes the file for you: /etc/cronbeat/key when run as root, ~/.config/cronbeat/key otherwise,
or the path from --key-file. It asks with hidden input; --stdin reads the key from standard input instead (for
provisioning scripts: printf '%s\n' "$KEY" | cronbeat configure --stdin).
cronbeat configure [--key-file FILE] [--stdin]cronbeat check [--api-url URL] [--key-file FILE]cronbeat versioncronbeat check sends one request to CronBeat, with a 10 second limit, and prints OK: the API key is valid, the host
agent name, the API address and where the key came from. It exits with 0 when the key is valid and 1 otherwise
(unreachable, 401, 403, or a Kubernetes key). 64 means wrong arguments.
Exit codes
Section titled “Exit codes”cronbeat run exits with the exit code of your command. CronBeat problems never change it.
| Exit code | When |
|---|---|
0 |
The command succeeded. Reported as succeeded. |
1 to 255 |
The command’s own exit code. Any value other than 0 is reported as failed with exit code N. |
128 + n |
The command was killed by signal n (137 for SIGKILL, 143 for SIGTERM). CronBeat gets the signal name, for example terminated by signal SIGKILL. |
127 |
The command was not found (like a shell). Reported as failed. |
126 |
The command exists but cannot be executed (permissions, wrong format). Reported as failed. |
64 |
Usage error: no command after --. The only case where nothing runs. |
70 |
An internal error of cronbeat itself. Not expected. |
SIGINT, SIGTERM, SIGHUP and SIGQUIT that reach cronbeat are forwarded to the process group of the command, so
systemctl stop or kill also reach the grandchildren. Standard input is passed through, and standard output and error
are passed through unchanged, in order. If cronbeat itself is killed with SIGKILL (for example by the out-of-memory
killer), it cannot send the result.
A background process that your job leaves running and that keeps stdout or stderr open would keep cronbeat waiting for
the end of the output. It waits 2 seconds after the command ended and then stops reading. Redirect the output of such
processes (> /dev/null 2>&1).
Output
Section titled “Output”The tail of the output is the reason most failures are quick to fix, so cronbeat keeps it, but only sends it when it
helps.
--output failure(default): stdout and stderr are kept in order in a ring buffer (the last--tail-bytes, default 4096, at most 8192). When the command fails, the tail is masked and sent. When it succeeds, nothing is sent.--output never: nothing is captured or sent. Use it for jobs whose output you do not want to leave the server.--output always: the tail is also sent for successful runs. CronBeat stores the output of failed runs only, so for a successful run it has no effect on what you see in the app.
The output still reaches your terminal, the cron mail or the journal exactly as before. When stdout or stderr is a
terminal nothing is captured, and a job that redirects its own output to a file (> job.log) leaves nothing to capture.
Partial UTF-8 characters at the cut are dropped and NUL bytes are removed.
Secrets in the tail are masked on the server where the job runs, before sending, see Data and security.
Time zones
Section titled “Time zones”A cron schedule only means something with a time zone. Cron runs a job in the local time of the server, so the monitor must use the same zone.
- With
--timezone, that zone is sent. - Without it, and only when
--scheduleis given,cronbeatdetects the zone of the server in this order:- the
TZenvironment variable (a leading:is ignored), - the file
/etc/timezone, - the link
/etc/localtime, when it points into azoneinfodirectory.
- the
- A zone is only accepted in the form
UTCorArea/Location(for exampleEurope/IstanbulorEtc/UTC). Names without a slash such asEST5EDTorGMTare not recognised: pass--timezone. - If nothing is found (for example in a minimal container image), no zone is sent and CronBeat uses
UTC. The same happens to an existing monitor when a run sends a schedule without a zone, so a server in another zone should be detected correctly or you should pass--timezone. - A zone that is not a valid IANA name is refused by CronBeat (HTTP 400) and the run is not reported.
The schedule, the zone and the name belong to the command line: when you change them, the next run updates the monitor. If you rename the monitor in the app, the next run sets the name back.
Grace period and maximum runtime
Section titled “Grace period and maximum runtime”--grace and --max-runtime are read once, when the monitor is created. After that they belong to the app: change
them under the monitor’s settings, and later changes to the flags are ignored (so your edits are never overwritten).
The maximum runtime is enforced by CronBeat, not by the command: when a started event arrived and no result follows
within the maximum runtime, the monitor goes down with the reason too_long. cronbeat does not kill your job.
Examples
Section titled “Examples”A backup script with a generous grace period and a maximum runtime:
cronbeat run --name nightly-backup --schedule "0 2 * * *" --grace 15m --max-runtime 3h -- /opt/backup.sh --fullA Python job in a given time zone, in a crontab (absolute paths, because cron’s PATH is short):
0 7 * * 1-5 /usr/local/bin/cronbeat run --name daily-report --schedule '0 7 * * 1-5' --timezone Europe/Istanbul -- /usr/bin/python3 /opt/report/main.py --dailyA Node.js job every ten minutes with more output kept for diagnosis:
*/10 * * * * /usr/local/bin/cronbeat run --name sync-orders --schedule '*/10 * * * *' --tail-bytes 8192 -- /usr/bin/node /srv/app/jobs/sync-orders.jsA job whose output must never leave the server:
cronbeat run --name export-customers --schedule "@daily" --output never -- /opt/export.shA shell pipeline (the exit code is the one of the shell, so use set -o pipefail if you need the failure of the first
command; pipefail needs bash):
cronbeat run --name db-dump --schedule "30 1 * * *" -- /bin/bash -c 'set -o pipefail; pg_dump mydb | gzip > /backup/mydb.sql.gz'Warnings
Section titled “Warnings”Problems with CronBeat itself (no key, wrong key, network, plan limit, server errors) are printed to stderr as
cronbeat: warning: ..., never to stdout. Cron mails output to MAILTO, so to keep a broken connection from filling a
mailbox each kind of warning is shown at most once per 6 hours (the time is remembered in
~/.cache/cronbeat/warned.json, best effort: if that file cannot be written, warnings appear on every run).
--verbose shows every warning and the steps on every run.
| Warning | Meaning |
|---|---|
no API key configured |
No key in any of the four places. The job ran without monitoring. |
CronBeat rejected the API key (HTTP 401) |
The key is wrong or revoked. |
CronBeat refused this job (HTTP 403) |
For example plan_limit_exceeded: the monitor limit or the host limit of the plan is reached, or the key is not a host agent key. The job ran. |
CronBeat rejected the report (HTTP 400) |
Invalid data, for example no --schedule on the first run or an invalid cron expression or time zone. |
CronBeat is rate limiting this host (HTTP 429) |
More than 600 requests per minute with this key. |
could not reach CronBeat (...) |
Network, DNS or certificate problem. |
Network behaviour
Section titled “Network behaviour”cronbeat is built so that CronBeat being slow or down does not slow or break your job.
startedis sent in the background and never delays the command: 2 seconds to connect, 4 seconds in total, one attempt.- The result (
succeededorfailed) is sent after the command ended. Before that,cronbeatwaits for the start event to finish (at most 4 seconds), so the order is kept. The result is tried up to 3 times, 4 seconds per attempt, with waits of 0.3 and 0.9 seconds (aRetry-Afterheader is honoured up to 3 seconds), within about 12 seconds in total. Client errors such as 400, 401 and 403 are not retried. - Nothing is queued for later. A result that could not be delivered is lost, and without a result the monitor can go
lateand thendown(or showtoo_long). Keep this in mind when the server has no network at the time a job ends. - Each run has a random run id (UUID v4); a retry of the same run is safe because CronBeat de-duplicates by it.
HTTPS_PROXYis used if set. Redirects are not followed.

