crontab設(shè)置每分鐘、每小時(shí)、每天、每周、每月、每年定時(shí)執(zhí)行的腳本
crontab設(shè)置每分鐘、每小時(shí)、每天、每周、每月、每年定時(shí)執(zhí)行
crontab的語法格式:
crontab每分鐘定時(shí)執(zhí)行:
*/1 * * * * service mysqld restart //每隔1分鐘執(zhí)行一次
*/10 * * * * service mysqld restart //每隔10分鐘執(zhí)行一次
crontab每小時(shí)定時(shí)執(zhí)行:
0 */1 * * * service mysqld restart //每1小時(shí)執(zhí)行一次
0 */2 * * * service mysqld restart //每2小時(shí)執(zhí)行一次
crontab每天定時(shí)執(zhí)行:
0 10 * * * service mysqld restart //每天10點(diǎn)執(zhí)行
30 19 * * * service mysqld restart //每天19點(diǎn)30分執(zhí)行
crontab每周定時(shí)執(zhí)行:
0 10 * * 1 service mysqld restart //每周一10點(diǎn)執(zhí)行
30 17 * * 5 service mysqld restart //每周五17點(diǎn)30分執(zhí)行
crontab每年定時(shí)執(zhí)行:
0 10 1 10 * service mysqld restart //每年的10月1日10點(diǎn)執(zhí)行
0 20 8 8 * service mysqld restart //每年的8月8日20點(diǎn)執(zhí)行
補(bǔ)充:crontab 每隔1小時(shí) 2小時(shí)的執(zhí)行job寫法
加任務(wù):
crontab -e
0 */1 * * * command
0 */2 * * * command
查詢?nèi)蝿?wù)是否加了:
crontab -l
0 */1 * * * command
0 */2 * * * command
基本格式 :
* * * * * command
分 時(shí) 日 月 周 命令
第1列表示分鐘1~59 每分鐘用*或者 */1表示
第2列表示小時(shí)0~23(0表示0點(diǎn))
第3列表示日期1~31
第4列表示月份1~12
第5列標(biāo)識號星期0~6(0表示星期天)
第6列要運(yùn)行的命令
crontab文件的一些例子:
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
每一小時(shí)重啟apache
* 23-7/1 * * * /usr/local/etc/rc.d/lighttpd restart
晚上11點(diǎn)到早上7點(diǎn)之間,每隔一小時(shí)重啟apache
0 11 4 * mon-wed /usr/local/etc/rc.d/lighttpd restart
每月的4號與每周一到周三的11點(diǎn)重啟apache
0 4 1 jan * /usr/local/etc/rc.d/lighttpd restart
一月一號的4點(diǎn)重啟apache
到此這篇關(guān)于crontab設(shè)置每分鐘、每小時(shí)、每天、每周、每月、每年定時(shí)執(zhí)行的文章就介紹到這了,更多相關(guān)crontab定時(shí)執(zhí)行內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
- Linux之crontab定時(shí)執(zhí)行腳本方式
- django-crontab 定時(shí)執(zhí)行任務(wù)方法的實(shí)現(xiàn)
- Linux crontab定時(shí)執(zhí)行Shell腳本需要執(zhí)行特定的命令時(shí)解決思路
- Linux下的crontab定時(shí)執(zhí)行任務(wù)命令詳解
- Linux定時(shí)執(zhí)行任務(wù)at和crontab命令詳解
- Ubuntu系統(tǒng)下用Crontab命令定時(shí)執(zhí)行PHP文件詳解
- Centos 7下利用crontab定時(shí)執(zhí)行任務(wù)詳解
- linux下定時(shí)執(zhí)行任務(wù)的方法及crontab 用法說明(收集整理)
- 如何使用Linux的Crontab定時(shí)執(zhí)行PHP腳本的方法
相關(guān)文章
centos/rhel下實(shí)現(xiàn)nginx自啟動腳本實(shí)例
這篇文章主要介紹了centos/rhel下實(shí)現(xiàn)nginx自啟動腳本,需要的朋友可以參考下2014-07-07Linux Shell+Curl網(wǎng)站健康狀態(tài)檢查腳本,抓出中國博客聯(lián)盟失聯(lián)站點(diǎn)
這篇文章主要介紹了Shell+Curl網(wǎng)站健康狀態(tài)檢查腳本,抓出中國博客聯(lián)盟失聯(lián)站點(diǎn),需要的朋友可以參考下2016-02-02shell腳本實(shí)現(xiàn)隨機(jī)生成10個8位密碼
這篇文章主要介紹了shell腳本實(shí)現(xiàn)隨機(jī)生成10個8位密碼的方法,這里推薦給大家,有需要的小伙伴的可以參考下。2015-03-03Linux shell ftp命令根據(jù)文件日期下載文件的方法
最近做項(xiàng)目遇到這樣的需求要求ftp獲取遠(yuǎn)程數(shù)據(jù)的文件,根據(jù)文件的創(chuàng)建時(shí)間點(diǎn)下載文件。下面小編給大家分享知識點(diǎn)小結(jié),感興趣的朋友要求看看吧2017-09-09