OSDN Git Service

Regular updates
[twpd/master.git] / cron.md
1 ---
2 title: Cron
3 category: CLI
4 layout: 2017/sheet
5 updated: 2018-05-03
6 weight: -3
7 ---
8
9 ## Format
10 {: .-two-column}
11
12 ### Format
13
14 ```
15 Min  Hour Day  Mon  Weekday
16 ```
17 {: .-setup}
18
19 ```
20 *    *    *    *    *  command to be executed
21 ```
22
23 ```
24 ┬    ┬    ┬    ┬    ┬
25 │    │    │    │    └─  Weekday  (0=Sun .. 6=Sat)
26 │    │    │    └──────  Month    (1..12)
27 │    │    └───────────  Day      (1..31)
28 │    └────────────────  Hour     (0..23)
29 └─────────────────────  Minute   (0..59)
30 ```
31 {: .-setup.-box-chars}
32
33 ### Examples
34
35 | Example        | Description           |
36 | ---            | ---                   |
37 | `0 * * * *`    | every hour            |
38 | `*/15 * * * *` | every 15 mins         |
39 | `0 */2 * * *`  | every 2 hours         |
40 | `0 0 * * 0`    | every Sunday midnight |
41 | ---            | ---                   |
42 | `@reboot`      | every reboot          |
43
44 ### Crontab
45
46 ```bash
47 # Adding tasks easily
48 echo "@reboot echo hi" | crontab
49 ```
50
51 ```bash
52 # Open in editor
53 crontab -e
54 ```
55
56 ```bash
57 # List tasks
58 crontab -l [-u user]
59 ```