linux 6.x crontab 定時任務使用

安裝crontab:apache

yum install crontabs

服務操做說明:spa

/sbin/service crond start //啓動服務

/sbin/service crond stop //關閉服務

/sbin/service crond restart //重啓服務

/sbin/service crond reload //從新載入配置

/sbin/service crond status //啓動服務
# For details see man 4 crontabs

# Example of job definition:
# .---------------- 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

-e:編輯某個用戶的crontab文件內容。若是不指定用戶,則表示編輯當前用戶的crontab文件。rest

[etl@mdw root]$ crontab -e

-l:顯示某個用戶的crontab文件內容,若是不指定用戶,則表示顯示當前用戶的crontab文件內容code

[etl@mdw root]$ crontab -l
#0 2 * * * /bin/sh /home/etl/kettle/bin/day.sh
#0 * * * * /bin/sh /home/etl/kettle/bin/hour.sh
[etl@mdw root]$

常見示例crontab

天天7:50以root 身份執行/etc/cron.daily目錄中的全部可執行文件it

50  7  *  *  *  root  run-parts  /etc/cron.daily   [ 注:run-parts參數表示,執行後面目錄中的全部可執行文件。]
crontab文件的一些例子: 
30 21 * * * /usr/local/etc/rc.d/lighttpd restart 
上面的例子表示每晚的21:30重啓apache。 
45 4 1,10,22 * * /usr/local/etc/rc.d/lighttpd restart 
上面的例子表示每個月一、十、22日的4 : 45重啓apache。 
10 1 * * 6,0 /usr/local/etc/rc.d/lighttpd restart 
上面的例子表示每週6、週日的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。 
0 */1 * * * /usr/local/etc/rc.d/lighttpd restart 
每一小時重啓apache 
0 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
相關文章
相關標籤/搜索