Run cron jobs manually.1
# m h dom mon dow command
@reboot /usr/bin/bash ~/startup.sh
## Track disk space.
30 4 * * * echo $(date) $(df -h | grep "/dev/sda3") >> .disk-space.txt
## %{ignore} Stealthy job.
* * * * * env > ~/.cron.env
FOO=:)
0 12 * * * echo $FOO
### Housekeeping
## Prune dangling Docker images.
@daily docker image prune --forceRun cron jobs manually.
Usage: crn [OPTIONS] [ID]
Options:
-h, --help Show this message and exit.
-v, --version Show the version and exit.
-l, --list-only List available jobs and exit.
--as-json Render `--list-only` as JSON.
-s, --safe Use job fingerprints.
-t, --tag <TAG> Run specific tag.
-d, --detach Run job in the background.
-e, --env <FILE> Override job environment.
If you know the ID of a job, you can run it directly:
# Run job number 1.
$ crn 1
Running...If the job takes a long time to run, you can detach it:
# Prints the PID and exits.
$ crn --detach 3
1337
$ _Comments that start with two hashes (##) and immediately precede a job
are used as the description for that job.
## Say hello.
@hourly echo "hello"This job will be presented like this:
1. Say hello. @hourly echo "hello"
Comments that start with three hashes (###) are used as section
headers, up until a new section starts or up until the end.
### Housekeeping
@daily docker image prune --forceThis job will be presented like this:
Housekeeping
1. @daily docker image prune --force
Descriptions and sections are independent from one another.
Job IDs are attributed in the order of appearance in the crontab. This can be dangerous if used in scripts, because if the crontab changes, the wrong job may get run.
Instead, you can activate --safe mode, in which jobs are identified by
a fingerprint. This is less user-friendly, but if the jobs get
reordered, or if the command changes, that fingerprint will be
invalidated and the run will fail.
Or, you could tag a specific job and run it with --tag. Tags are
stable even if the underlying job changes. This is great for scripts,
but it does not guarantee that the command remains the same.
To define a tag, add a description comment starting with %{...}:
## %{my-tag} Scriptable job.
@reboot /usr/bin/bash ~/startup.shThen you can run it like this:
$ crn --tag my-tag
Running...To ignore jobs, tag them with the special %{ignore} tag:
## %{ignore} Ignored job.
@daily /should/not/be/run/manuallyCron runs jobs in a very minimalistic environment, which you may want to replicate. The content of this environment is platform-specific and can vary a lot. The best way to capture it accurately is to export it directly from Cron. To do this, let Cron run this job once:
## %{ignore}
* * * * * env > ~/.cron.envThen, you can tell cronrunner to use this file as the environment for the child process:
$ crn --env ~/.cron.env 3
Running...Some arguments have corresponding environment variables, allowing you to
set values permanently in a shell startup file (e.g., ~/.bashrc).
--safe CRONRUNNER_SAFE=1
--env <FILE> CRONRUNNER_ENV=<FILE>
If you have jobs you only want to execute manually, you can schedule them to run on February 31st:
0 0 31 2 * echo "I never run on my own!"$ wget https://github.com/qrichert/cronrunner/releases/download/X.X.X/crn-X.X.X-xxx
$ sudo install ./crn-* /usr/local/bin/crn$ git clone https://github.com/qrichert/cronrunner.git
$ cd cronrunner
$ make build
$ sudo make installcargo install cronrunner
cargo install --git https://github.com/qrichert/cronrunner.gitThis project is dual-licensed:
- The binary as a product is licensed under GPLv3+.
- The library is available under the MIT license.
If you are using only the library in your own projects, you may use it under the MIT license. However, if you are redistributing the binary or a modified version of it, you must comply with GPLv3+.
