linux 中crontab格式詳細說明

來源:互聯網
上載者:User

crontab是linux中一個常用的定時功能,也可以叫做是計劃任務功能了,下面我來介紹crontab命令的一些格式與用法。

crontab是絕大多數Linux發行版都內建的一個定時執行程式的服務。通過crontab -e命令可以開啟一個文字編輯器編輯目前使用者的定時任務。

具體格式如下:

名稱 : crontab

使用許可權 : 所有使用者

使用方式 :

crontab file [-u user]-用指定的檔案替代目前的crontab。

crontab-[-u user]-用標準輸入替代目前的crontab.

crontab-1[user]-列出使用者目前的crontab.

crontab-e[user]-編輯使用者目前的crontab.

crontab-d[user]-刪除使用者目前的crontab.

crontab-c dir- 指定crontab的目錄。

crontab檔案的格式:M H D m d cmd.


1 每行一個任務

2 每個任務分類6列,每列中間用空格或者tab間隔

3 前5列代表定時的周期,最後一列代表程式

4 前5列的順序依次為:分 時 日 月 星期

5 表示僅某時執行就寫具體的時間,每個周期都執行就用*代表

舉幾個具體的例子:

1 * * * * command(每小時的1分執行命令,比如:0點零1分,1點零1分……)
* * * * * command(每分鐘都執行,每天執行1440次)
0 0 1 * * command(每月1號0點0分執行)

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
一月一號的4點重啟apache

聯繫我們

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