CentOS下crontab中的宏

來源:互聯網
上載者:User

一、時間欄的定義
使用crontab -e可編譯計劃任務,格式為:

引用* * * * * 命令
前面的五個*號,表示分、時、日、月、周


cron服務的最少間隔周期為1分鐘,即每1分鐘cron服務會檢查一次系統中儲存的計劃任務資訊。
而時間欄的定義為:

引用field allowed values
----- --------------
minute 0-59
hour 0-23
day of month 1-31
month 1-12 (或者月份的簡寫)
day of week 0-7 (0 or 7,7是周日,或者使用簡寫)


若表示範圍,可使用:

引用* 代表全部,任意匹配;
- 表示範圍,例如:在分鐘欄,0-10,就是0到10分;
/ 表示間隔,例如:在分鐘欄,*/5,就是每5分鐘,小時欄,0-23/2,就是每2小時;


二、宏
除使用上述寫法外,還可以使用“nicknames”的定義:

引用@reboot : Run once, at startup.
@yearly : Run once a year, ie. "0 0 1 1 *".
@annually : Run once a year, ie. "0 0 1 1 *".
@monthly : Run once a month, ie. "0 0 1 * *".
@weekly : Run once a week, ie. "0 0 * * 0".
@daily : Run once a day, ie. "0 0 * * *".
@hourly : Run once an hour, ie. "0 * * * *".


三、舉例
每15分鐘執行一次:

引用*/15 * * * * /opt/test.sh
0,15,30,45 * * * * /opt/test.sh


每日的0時0分執行一次:

引用@daily /opt/test.sh
0 0 * * * /opt/test.sh


啟動的時候自動執行(相當於放到rc.local中):

引用@reboot /opt/test.sh


更詳細的資訊,請看man 5 crontab。

下載檔案

crontab.5.man.txt


聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.