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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM