Linux 下crontab簡單使用,linuxcrontab

來源:互聯網
上載者:User

Linux 下crontab簡單使用,linuxcrontab
0.個人標記caicongyanghttp://blog.csdn.net/caicongyang1.crontab

crontab是linux下的一個定時任務,在sping中也有該機制

2.基本格式

*  *  *  *  *  command
分 時  日   月  周   命令

3.命令

usage:  crontab [-u user] file        crontab [-u user] [ -e | -l | -r ]                (default operation is replace, per 1003.2)        -e      (edit user's crontab)        -l      (list user's crontab)        -r      (delete user's crontab)        -i      (prompt before deleting user's crontab)        -s      (selinux context)
crontab –u //設定某個使用者的cron服務,一般root使用者在執行這個命令的時候需要此參數 
crontab –l //列出某個使用者cron服務的詳細內容 
crontab –r //刪除某個使用者的cron服務 
crontab –e //編輯某個使用者的cron服務 
crontab filename //以filename作為crontab的工作清單檔案並載入 
比如說root查看自己的cron設定:crontab –u root –l 
再例如,root想刪除fred的cron設定:crontab –u fred –r 
在編輯cron服務時,編輯的內容有一些格式和約定,輸入:crontab –u root –e 

4.重新啟動

修改了crontab需要重新啟動,以下命令分別提供了查看crontab的狀態和重啟

#service crond status#service crond restart

5.列子

#每天早上6點10分 
10    6     *     *     *     date 
#每兩個小時 
0     */2   *     *     *     date 
#晚上11點到早上8點之間每兩個小時,早上8點 
0     23-7/2,8      *     *     *     date 
#每個月的4號和每個礼拜一到礼拜三的早上11點 
0     11    4     *     1-3  date 
#1月1日早上4點 
0     4     1     1       *  date 

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


我的CSDN部落格地址: http://blog.csdn.net/caicongyang 












聯繫我們

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