通過linux的crontab實現定時執行shell指令碼功能__linux

來源:互聯網
上載者:User
轉貼:

http://blog.csdn.net/allenlinrui/article/details/7490206


使用crontab你可以在指定的時間執行一個shell指令碼或者一系列Linux命令。例如系統管理員安排一個備份任務使其每天都運行

入門

# crontab –e

這樣可以已編輯模式開啟個人的crontab設定檔,然後加入一下這行:
0 0 * * * /home/linrui/XXXXXXXX.sh

這將會在每天淩晨運行 指定的.sh檔案


Cron 各項的描述

以下是 crontab 檔案的格式:

{minute} {hour} {day-of-month} {month} {day-of-week} {full-path-to-shell-script} 
o minute: 區間為 0 – 59 
o hour: 區間為0 – 23 
o day-of-month: 區間為0 – 31 
o month: 區間為1 – 12. 1 是1月. 12是12月. 
o Day-of-week: 區間為0 – 7. 周日可以是0或7.


Crontab 樣本

1、在 淩晨00:01運行

1 0 * * * /home/linrui/XXXX.sh

2、每個工作日11:59都進行備份作業。

59 11 * * 1,2,3,4,5 /home/linrui/XXXX.sh   

或者如下寫法:

59 11 * * 1-5 /home/linrui/XXXX.sh

3、每分鐘運行一次命令

*/1 * * * * /home/linrui/XXXX.sh

4、每個月的1號 14:10 運行

10 14 1 * * /home/linrui/XXXX.sh


Crontab命令的選項

以下是 crontab 的有效選項:

crontab –e : 修改 crontab 檔案. 如果檔案不存在會自動建立。 
crontab –l : 顯示 crontab 檔案。 
crontab -r : 刪除 crontab 檔案。
crontab -ir : 刪除 crontab 檔案前提醒使用者。

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.