Differences
This shows you the differences between two versions of the page.
linux_wiki:cron [2017/09/03 16:43] billdozor [Files That Control Access] |
linux_wiki:cron [2019/05/25 23:50] |
||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== Cron ====== | ||
- | **General Information** | ||
- | |||
- | Automating tasks with Cron. | ||
- | |||
- | **Checklist** | ||
- | * Distro(s): Any | ||
- | |||
- | ---- | ||
- | |||
- | ====== User Crontabs ====== | ||
- | |||
- | List your user's crontab jobs | ||
- | <code bash> | ||
- | crontab -l | ||
- | </ | ||
- | |||
- | Edit your crontab | ||
- | <code bash> | ||
- | crontab -e | ||
- | </ | ||
- | |||
- | ===== Files That Control Crontab Access ===== | ||
- | |||
- | * / | ||
- | * / | ||
- | |||
- | About these files: | ||
- | * One username per line | ||
- | * Root can always use cron | ||
- | |||
- | ^ cron.allow | ||
- | | file exists | ||
- | | no file | file exists | ||
- | | file exists | ||
- | |||
- | ---- | ||
- | |||
- | ===== Format of User Crontabs ===== | ||
- | |||
- | For any below, asterisk means all values. | ||
- | <code bash> | ||
- | # m = minute (0-59) | ||
- | # h = hour (0-23) | ||
- | # dom = day of month(1-31) | ||
- | # mon = month (1-12) | ||
- | # dow = day of week (0-7, 0 or 7 is Sunday) | ||
- | # cmd = command (command or path to script) | ||
- | |||
- | # m h dom mon dow cmd | ||
- | </ | ||
- | |||
- | ---- | ||
- | |||
- | ====== Examples ====== | ||
- | |||
- | Executes script.sh at 0600, | ||
- | <code bash> | ||
- | 0,30 6,12 * * * / | ||
- | </ | ||
- | |||
- | Executes script.sh every minute. | ||
- | <code bash> | ||
- | * * * * * / | ||
- | </ | ||
- | |||
- | Executes script.sh every 5 minutes. | ||
- | <code bash> | ||
- | */5 * * * * / | ||
- | </ | ||
- | |||
- | Executes script.sh on system startup. | ||
- | <code bash> | ||
- | @reboot / | ||
- | </ | ||
- | |||
- | ===== Other Cron keywords ===== | ||
- | |||
- | * @reboot - Run once at start up. | ||
- | * @yearly - Run once a year. | ||
- | * @annually - Same as yearly. | ||
- | * @monthly - Run once a month. | ||
- | * @weekly - Run once a week. | ||
- | * @daily - Run once a day. | ||
- | * @midnight - Same as daily. | ||
- | * @hourly - Run once an hour. | ||
- | |||
- | ---- | ||
- | |||
- | ====== System Cron Jobs ====== | ||
- | |||
- | To run jobs in the system directories, | ||
- | |||
- | * / | ||
- | * / | ||
- | * / | ||
- | * / | ||
- | * / | ||
- | * / | ||
- | |||
- | It is recommended to drop scripts into one of the /etc/cron.* directories instead of editing the system wide crontab file. | ||
- | |||
- | All formats are bash scripts, except for the / | ||
- | |||
- | For example, / | ||
- | <code bash> | ||
- | # Rsync the crashplan backups to another usb drive for redundancy | ||
- | 0 2,14 * * * root / | ||
- | </ | ||
- | The above executes at 0200 and 1400, runs as the user root, the script specified. |