crond服務是Linux的內置服務,即crontab。 須要設置開機啓動: 在 /etc/rc.d/rc.local 腳本中加入apache
/sbin/service crond start
當前用戶的crontabbash
crontab -l
進入crontab定時任務設置,其實就是其配置文件的vi編輯:rest
crontab -e
# .---------------- minute (0 - 59) # | .------------- hour (0 - 23) # | | .---------- day of month (1 - 31) # | | | .------- month (1 - 12) OR jan,feb,mar,apr ... # | | | | .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat # | | | | | # * * * * * user-name command to be executed
以上的說明可能還有點讓人發暈,能夠看一下如下這種說明code
minute hour day-of-month month-of-year day-of-week commands 合法值 00-59 00-23 01-31 01-12 0-6 (0 is sunday) (例如: sh /home/test.sh)
再舉幾個例子
每分鐘向/home/zhengwei_crontest/mycrontab.log中打印一行記錄:crontab
* * * * * echo "master_sync.sh execute at time:"$(date) >> /home/zhengwei_crontest/mycrontab.log
每晚10點執行master_sync.sh腳本:ast
0 22 * * * /bin/sh /opt/code/nisp/tool/master_sync.sh
每2小時重啓apache lighttpdclass
0 */2 * * * /usr/local/etc/rc.d/lighttpd restart
你們本身能夠按需設置test
service crond reload service crond restart