vi /etc/crontabnginx
安裝crontab:
yum install crontabsrest
說明:
/sbin/service crond start //啓動服務
/sbin/service crond stop //關閉服務
/sbin/service crond restart //重啓服務
/sbin/service crond reload //從新載入配置crontab
查看crontab服務狀態:service crond statusget
手動啓動crontab服務:service crond start同步
查看crontab服務是否已設置爲開機啓動,執行命令:ntsysvhash
加入開機自動啓動:
chkconfig –level 35 crond onit
1,crontab命令配置
功能說明:設置計時器。date
語 法:crontab [-u <用戶名稱>][配置文件] 或 crontab [-u <用戶名稱>][-elr]service
補充說明:cron是一個常駐服務,它提供計時器的功能,讓用戶在特定的時間得以執行預設的指令或程序。只要用戶會編輯計時器的配置文件,就能夠使 用計時器的功能。其配置文件格式以下:
Minute Hour Day Month DayOFWeek Command
參 數:
-e 編輯該用戶的計時器設置。
-l 列出該用戶的計時器設置。
-r 刪除該用戶的計時器設置。
-u<用戶名稱> 指定要設定計時器的用戶名稱。
2,crontab 格式
基本格式 :
* * * * * command
分 時 日 月 周 命令
第1列表示分鐘1~59 每分鐘用*或者 */1表示
第2列表示小時1~23(0表示0點)
第3列表示日期1~31
第4列 表示月份1~12
第5列標識號星期0~6(0表示星期天)
第6列要運行的命令
# Use the hash sign to prefix a comment
# +—————- minute (0 – 59)
# | +————- hour (0 – 23)
# | | +———- day of month (1 – 31)
# | | | +——- month (1 – 12)
# | | | | +—- day of week (0 – 7) (Sunday=0 or 7)
# | | | | |
# * * * * * command to be executed
crontab文件的一些例子:
30 21 * * * /etc/init.d/nginx restart
每晚的21:30重啓 nginx。
45 4 1,10,22 * * /etc/init.d/nginx restart
每個月一、 十、22日的4 : 45重啓nginx。
10 1 * * 6,0 /etc/init.d/nginx restart
每週6、週日的1 : 10重啓nginx。
0,30 18-23 * * * /etc/init.d/nginx restart
天天18 : 00至23 : 00之間每隔30分鐘重啓nginx。
0 23 * * 6 /etc/init.d/nginx restart
每星期六的11 : 00 pm重啓nginx。
* */1 * * * /etc/init.d/nginx restart
每一小時重啓nginx
* 23-7/1 * * * /etc/init.d/nginx restart
晚上11點到早上7點之間,每 隔一小時重啓nginx
0 11 4 * mon-wed /etc/init.d/nginx restart
每個月的4號與每週一到週三 的11點重啓nginx
0 4 1 jan * /etc/init.d/nginx restart
一月一號的4點重啓nginx
*/30 * * * * /usr/sbin/ntpdate 210.72.145.20 每半小時同步一下時間