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 ### Operators
34
35 | Operator | Description                |
36 | ---      | ---                        |
37 | `*`      | all values                 |
38 | `,`      | separate individual values |
39 | `-`      | a range of values          |
40 | `/`      | divide a value into steps  |
41
42 ### Examples
43
44 | Example        | Description                 |
45 | ---            | ---                         |
46 | `0 * * * *`    | every hour                  |
47 | `*/15 * * * *` | every 15 mins               |
48 | `0 */2 * * *`  | every 2 hours               |
49 | `0 18 * * 0-6` | every week Mon-Sat at 6pm   |
50 | `10 2 * * 6,7` | every Sat and Sun on 2:10am |
51 | `0 0 * * 0`    | every Sunday midnight       |
52 | ---            | ---                         |
53 | `@reboot`      | every reboot                |
54
55 ### Crontab
56
57 ```bash
58 # Adding tasks easily
59 echo "@reboot echo hi" | crontab
60 ```
61
62 ```bash
63 # Open in editor
64 crontab -e
65 ```
66
67 ```bash
68 # List tasks
69 crontab -l [-u user]
70 ```