This document is a WORK IN PROGRESS.
This is just a quick personal cheat sheet: treat its contents with caution!
cron¶
cron is a daemon that runs scheduled tasks based on input from the command crontab. It
accomplishes this task by waking up every minute and checking to see if there are any cron jobs to
run in any of the user crontabs.
Reference(s)
Table of contents¶
Install¶
There are multiple cron implementations, in this cheat sheet I will use cronie (fork of
vixie-cron, because according to the Gentoo Wiki:
vixie-cron is a bit outdated while still maintained by Fedora).
First, check if cronie is already installed:
Warning to NixOS users
There is no cronie nix package, only cron (which is vixie-cron), so for the rest
of this cheat sheet: remember to replace any cronie reference by cron. But be
warned that the following sections may not correctly apply to vixie-cron.
If not, install it ...
Then, add it to your init system and start it:
Depending on your runit implementation, either run:
Config¶
cronie doesn't need to be configured anymore.
Old cronie config:
# vi /etc/crontab
> # Global variables
> SHELL=/bin/bash
> PATH=/sbin:/bin:/usr/sbin:/usr/bin
> MAILTO=root
> HOME=/
>
> # check scripts in cron.hourly, cron.daily, cron.weekly and cron.monthly
> 59 * * * * root rm -f /var/spool/cron/lastrun/cron.hourly
> 9 3 * * * root rm -f /var/spool/cron/lastrun/cron.daily
> 19 4 * * 6 root rm -f /var/spool/cron/lastrun/cron.weekly
> 29 5 1 * * root rm -f /var/spool/cron/lastrun/cron.monthly
> */10 * * * * root test -x /usr/sbin/run-crons && /usr/sbin/run-crons
Use¶
-
Edit your
crontab(crontabsare located in/var/spool/cron/crontabs): -
Add a line to the wanted
crontabaccording to this format: -
E.g. execute a command every ...
-
Check the file syntax of your
crontab: -
Delete your
crontab: -
By default one can check cron executions by reading the logs in
/var/log/messagesand searching forcron.
anacron¶
anacron is not a cron daemon, it is something that usually works in conjunction with one. It
executes commands at intervals specified in days and it does not assume that the system is running
continuously; it will run jobs that were missed while the system was down. anacron usually relies
on a cron daemon to run it each day.
By default cronie includes anacron functionalities (note to Gentoo users: cronie includes
anacron functionalities when the default anacron use flag is set).
If this cheat sheet has been useful to you, then please consider leaving a star here.