Fork me on GitHub

Linux crontab 的常用定时方式

Linux crontab 的常用定时方式


 

0、crontab文件的格式

M H D m d cmd 

M: 分钟(0-59)

H: 小时(0-23)

D: 天(1-31)

m: 月(1-12)

d: 一星期内的天(0~6,0为星期天)

cmd: 要运行的程序,程序被送入sh执行

 

1、crontab 每分钟 定时执行

*/1 * * * * service mysqld restart  //每隔1分钟执行一次
*/10 * * * * service mysqld restart //每隔10分钟执行一次

 

2、crontab 每小时 定时执行

0 */1 * * * service mysqld restart //每1小时执行一次
0 */2 * * * service mysqld restart //每2小时执行一次

 

3、crontab 每天 定时执行

0 10 * * * service mysqld restart  //每天10点执行
30 19 * * * service mysqld restart //每天19点30分执行

 

4、crontab 每周 定时执行

0 10 * * 1 service mysqld restart  //每周一10点执行
30 17 * * 5 service mysqld restart //每周五17点30分执行

 

5、 crontab 每月 定时执行

10 10 1 * * service mysqld restart  //每月的1日10点10分执行
20 20 30 * * service mysqld restart //每月的30日20点20分执行

 

6、crontab 每年 定时执行

0 10 1 10 * service mysqld restart //每年的10月1日10点执行
0 20 8 8 * service mysqld restart  //每年的8月8日20点执行

 

7、crontab 时间点、时间段 定时执行

3,15 * * * * service mysqld restart      //每小时的第3和第15分钟执行
3,15 8-11 * * *  service mysqld restart  //上午8点到11点的第3和第15分钟执行
10 10 1-29 * * service mysqld restart    //每月的1日到29日10点10分执行
10 10 1,3,5,7 * * service mysqld restart //每月的1/3/5/7日10点10分执行

30 21 * * * /usr/local/etc/rc.d/lighttpd restart      //每晚的21:30重启apache
45 4 1,10,22 * * /usr/local/etc/rc.d/lighttpd restart //每月1、10、22日的4:45重启apache
10 1 * * 6,0 /usr/local/etc/rc.d/lighttpd restart     //每周六、周日的1:10重启apache
0,30 18-23 * * * /usr/local/etc/rc.d/lighttpd restart //每天18:00至23:00之间每隔30分钟重启apache
0 23 * * 6 /usr/local/etc/rc.d/lighttpd restart       //每星期六的11:00 pm重启apache 
* */1 * * * /usr/local/etc/rc.d/lighttpd restart      //每一小时重启apache 
* 23-7/1 * * * /usr/local/etc/rc.d/lighttpd restart   //晚上11点到早上7点之间,每隔一小时重启apache 
0 11 4 * mon-wed /usr/local/etc/rc.d/lighttpd restart //每月的4号与每周一到周三的11点重启apache 
0 4 1 jan * /usr/local/etc/rc.d/lighttpd restart      //1月1号的4点重启apache 
0 6-12/3 * 12 * /usr/local/etc/rc.d/lighttpd restart  //12月份每天的早上6点到12点中,每隔3个小时执行一次

 

 

 

[参考文章]

https://www.caizhichao.cn/951.html

https://www.cnblogs.com/ultranms/p/9849846.html

https://cloud.tencent.com/developer/article/1200206

posted @ 2020-11-26 16:14  龙凌云端  阅读(1480)  评论(0编辑  收藏  举报