crontab scheduled task

The world rises and falls. The left side of the Hua Deng is on the right hand side. On the right hand side is the bustling star point

Crontab is a tool for customizing scheduled tasks under linux. It is easy to use and is an essential artifact for home travel and timing. This article records the use of crontab, as well as pay attention to pits.

Plan task basic format

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
```
* time division day month week order
* Column 1 indicates minutes 1 to 59. Each minute is represented by * or */1.
* Column 2 indicates hours 1 to 23 (0 means 0 points)
* Column 3 indicates date 1 to 31
* Column 4 indicates month 1 to 12
* Column 5 identification number week 0 ~ 6 (0 means Sunday)
* Column 6 to run the command
### crontab usage
* crontab -h view command help
* crontab -e edit schedule task
* sudo crontab -l lists the root's scheduled tasks
* crontab -u nmask -l lists the scheduled tasks for nmask
* crontab -r delete scheduled tasks
Generally, write a scheduled task, run crontab -e and then write the scheduled task, save and exit.
### Execution per second
```bash
* * * * * sleep 10;

Run every 10s.

Some examples of crontab files

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
30 21 * * * /usr/local/etc/rc.d/lighttpd restart means to restart apache every night at 21:30
45 4 1,10,22 * * /usr/local/etc/rc.d/lighttpd restart means 4:45 on the 1st, 10th, 22nd of each month
10 1 * * 6,0 /usr/local/etc/rc.d/lighttpd restart means restarting apache every Saturday and Sunday at 1:10
0,30 18-23 * * * /usr/local/etc/rc.d/lighttpd restart means to restart apache every 30 minutes between 18:00 and 23:00 every day.
0 23 * * 6 /usr/local/etc/rc.d/lighttpd restart Indicates that apache is restarted every Saturday at 11:00pm.
0 */1 * * * /usr/local/etc/rc.d/lighttpd restart Restart apache every hour
0 23-7/1 * * * /usr/local/etc/rc.d/lighttpd restart Restart apache every hour between 11pm and 7am
0 11 4 * mon-wed /usr/local/etc/rc.d/lighttpd restart Restart apache on the 4th of each month and 11am every Monday to Wednesday.
0 4 1 jan * /usr/local/etc/rc.d/lighttpd restart Restart apache at 4 o'clock on January 1st
1
2
*/1 * * * * Execution per minute
1 * * * * Execute once an hour

Note the above two scheduled tasks, one is executed every minute and the other is executed every hour.

test environment

If you are not sure if the planned task is correct, you can test it online: http://tool.lu/crontab/

本文标题:crontab scheduled task

文章作者:nmask

发布时间:2017年08月31日 - 14:08

最后更新:2019年08月16日 - 14:08

原始链接:https://thief.one/2017/08/31/1/en/

许可协议: 署名-非商业性使用-禁止演绎 4.0 国际 转载请保留原文链接及作者。

nmask wechat
欢迎您扫一扫上面的微信公众号,订阅我的博客!
坚持原创技术分享,您的支持将鼓励我继续创作!

热门文章推荐: