# Config : crontab \[ [man page](https://manpages.ubuntu.com/manpages/jammy/man5/crontab.5.html) ] ###### Basics - displayed with `crontab -l`, edited with `crontab -e`, not installed until you exit editor - commands executed as user in user's home dir - ignores leading spaces, blank lines, and lines who's first non-space char is `#` - active lines either set an env var or schedule a command ###### Env Vars `name = value` - only affects commands below the env var - quoting is optional (single or double) - leading spaces ignored, middle spaces included - values not parsed for tilde expansion or variable substitution - set by default: `HOME`, `LANG`, `LOGNAME`, `PATH`, `PWD`, `SHELL`, `SHLVL`, _ - default path: `/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin` ###### Commands - performs tilde and wildcard expansion and variable substitution - `%` = newline unless escaped with `\` - precede with `bash -lc` to load your profile and thus set `PATH` correctly ###### Schedules | minute | hour | day-of-month | month | day-of-week | | ------ | ---- | ------------ | ----------- | ----------- | | 0-59 | 0-23 | 1-31 | 1-12, Jan-Dec | 0-7, Sun-Sat | - fields separated by whitespace - matching logic: minute AND hour AND month-of-year AND (day-of-month OR day-of-week) - supports `*` as wildcard (matches all values) - supports lists: `1,3,5` - supports ranges: `5-10,15-20` - supports steps: `*/2`, `0-23/4` > [!info] Special Strings > Substitutes for the five time fields: > ```cron > @reboot Run once, at startup. > @yearly Run once a year, "0 0 1 1 *". > @annually Same as @yearly. > @monthly Run once a month, "0 0 1 * *". > @weekly Run once a week, "0 0 * * 0". > @daily Run once a day, "0 0 * * *". > @midnight Same as @daily. > @hourly Run once an hour, "0 * * * *". > ``` ###### Mail If a command produces output on `STDOUT` or `STDERR`, cron sends mail to `user@host` which ends up in `/var/spool/mail/<user>` unless mail delivery is configured. (see: [[Send to Gmail From Command-Line]]) - To change the `To:` and `From:` values, set `MAILTO` and `MAILFROM` at the top of the crontab. - To disable the sending of email, set `MAILTO=""`. - The mail fields only accept bare addresses, not `"Full Name <[email protected]>"` strings.