#vi /etc/crontab
看到下面幾個
# run-parts
01 * * * * root run-parts /etc/cron.hourly
02 4 * * * root run-parts /etc/cron.daily
22 5 * * 0 root run-parts /etc/cron.weekly
42 5 1 * * root run-parts /etc/cron.monthly
在/etc/cron.daily
下添加一個backup.sh(內容就寫最上面的sh腳本)就會每天執(zhí)行
重新啟動crond
# /etc/rc.d/init.d/crond restart
--------------------------
看一下crontab 的格式
第1列分鐘1~59
第2列小時1~23(0表示子夜)
第3列日1~31
第4列月1~12
第5列星期0~6(0表示星期天)
第6列要運行的命令
下面是crontab的格式:
分 時 日 月 星期 要運行的命令
這里有crontab文件條目的一些例子:
30 21 * * * /usr/local/apache/bin/apachectl restart
上面的例子表示每晚的21:30重啟apache。
45 4 1,10,22 * * /usr/local/apache/bin/apachectl restart
上面的例子表示每月1、10、22日的4 : 45重啟apache。
10 1 * * 6,0 /usr/local/apache/bin/apachectl restart
上面的例子表示每周六、周日的1 : 10重啟apache。
0,30 18-23 * * * /usr/local/apache/bin/apachectl restart
上面的例子表示在每天18 : 00至23 : 00之間每隔30分鐘重啟apache。
0 23 * * 6 /usr/local/apache/bin/apachectl restart
上面的例子表示每星期六的11 : 00 pm重啟apache。
) */1 * * * /usr/local/apache/bin/apachectl restart
每一小時重啟apache
0 23-7/1 * * * /usr/local/apache/bin/apachectl restart
晚上11點到早上7點之間,每隔一小時重啟apache
0 11 4 * mon-wed /usr/local/apache/bin/apachectl restart
每月的4號與每周一到周三的11點重啟apache
0 4 1 jan * /usr/local/apache/bin/apachectl restart