notebook/IT/Linux/Cron.md

57 lines
1.6 KiB
Markdown
Raw Permalink Normal View History

2020-11-26 17:38:25 +00:00
# cron
2021-04-20 21:13:14 +00:00
```bash
2020-11-26 17:38:25 +00:00
# * * * * * command to execute
# │ │ │ │ │
# │ │ │ │ │
# │ │ │ │ └───── day of week (0 - 6) (0 to 6 are Sunday to Saturday, or use names; 7 is Sunday, the same as 0)
# │ │ │ └────────── month (1 - 12)
# │ │ └─────────────── day of month (1 - 31)
# │ └──────────────────── hour (0 - 23)
# └───────────────────────── min (0 - 59)
```
2021-04-20 21:13:14 +00:00
2021-02-15 16:47:12 +00:00
[test cron](https://crontab.guru/)
2021-04-20 21:13:14 +00:00
2020-11-26 17:38:25 +00:00
See also
2021-04-20 21:13:14 +00:00
[wikipedia/cron](http://en.wikipedia.org/wiki/Cron)
2020-11-26 17:38:25 +00:00
## cron directories
2021-04-20 21:13:14 +00:00
2020-11-26 17:38:25 +00:00
You can create directories that run cron commands. Taken from the `Ubuntu`
distro:
2021-04-20 21:13:14 +00:00
2020-11-26 17:38:25 +00:00
```txt
# /etc/crontab: system-wide crontab
# Unlike any other crontab you don't have to run the `crontab'
# command to install the new version when you edit this file
# and files in /etc/cron.d. These files also have username fields,
# that none of the other crontabs do.
SHELL=/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
# m h dom mon dow user command
17 * * * * root cd / && run-parts --report /etc/cron.hourly
25 6 * * * root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.daily )
47 6 * * 7 root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.weekly )
52 6 1 * * root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.monthly )
```
## run every weekday at midnight
2021-04-20 21:13:14 +00:00
2020-11-26 17:38:25 +00:00
```sh
0 0 * * 0-5
```
## edit cronjobs
2021-04-20 21:13:14 +00:00
2020-11-26 17:38:25 +00:00
```sh
2021-04-20 21:13:14 +00:00
sudo crontab -e
2020-11-26 17:38:25 +00:00
```
2020-11-28 09:03:27 +00:00
2021-04-20 21:13:14 +00:00
## user crontab lcation
2020-11-28 09:03:27 +00:00
2021-02-15 16:47:12 +00:00
`/var/spool/cron/crontabs`