1、crontab相關命令
語法:crontab [-u <用戶名稱>][配置文件] 或 crontab [-u <用戶名稱>][-elr]
參數:
-e 編輯該用戶的計時器設置。
-l 列出該用戶的計時器設置。
-r 刪除該用戶的計時器設置。
-u<用戶名稱> 指定要設定計時器的用戶名稱。
2、啟動crontab
/bin/systemctl restart crond.service #啟動服務 /bin/systemctl reload crond.service #重新載入配置 /bin/systemctl status crond.service #查看crontab服務狀態
3、crontab 配置文件格式
基本格式 :
* * * * * command
分 時 日 月 周 命令
第1列表示分鍾1~59 每分鍾用*或者 */1表示
第2列表示小時1~23(0表示0點)
第3列表示日期1~31
第4列表示月份1~12
第5列標識號星期0~6(0表示星期天)
第6列要運行的命令
除了數字還有幾個個特殊的符號就是"*"、"/"和"-"、",",*代表所有的取值范圍內的數字,"/"代表每的意思,"*/5"表示每5個單位,"-"代表從某個數字到某個數字,","分開幾個離散的數字。
crontab文件的一些例子:
30 21 * * * /usr/local/etc/rc.d/apache restart #每晚的21:30 重啟apache 45 4 1,10,22 * * /usr/local/etc/rc.d/apache restart #每月1、10、22日的4 : 45重啟apache 10 1 * * 6,0 /usr/local/etc/rc.d/apache restart #每周六、周日的1 : 10重啟apache 0,30 18-23 * * * /usr/local/etc/rc.d/apache restart #每天18 : 00至23 : 00之間每隔30分鍾重啟apache 0 23 * * 6 /usr/local/etc/rc.d/apache restart #每星期六的11 : 00 pm重啟apache * 23-7/1 * * * /usr/local/etc/rc.d/apache restart #晚上11點到早上7點之間,每隔一小時重啟 apache * */1 * * * /usr/local/etc/rc.d/apache restart #每一小時重啟apache 0 11 4 * mon-wed /usr/local/etc/rc.d/apache restart #每月的4號與每周一到周三的11點重啟apache 0 4 1 jan * /usr/local/etc/rc.d/apache restart #一月一號的4點重啟apache */30 * * * * /usr/sbin/ntpdate 210.72.145.44 #每半小時同步一下時間 0 */2 * * * www /usr/bin/somecommand >> /dev/null 2>&1 #以用戶www的身份每兩小時就運行某個程序:
參考:https://my.oschina.net/yangalbert/blog/496494?p={{totalPage}}
<embed src="//music.163.com/style/swf/widget.swf?sid=3213251&type=1&auto=1&width=310&height=430" width="330" height="450" allowNetworking="all"></embed>