--crontab
檢查是否安裝
[oracle@rac1 ~]$ rpm -qa | grep crontab
crontabs-1.10-8
啓動與關閉
[oracle@rac1 ~]$ /etc/init.d/crond stop/start/restart/reload
全局配置文件
[root@rac1 ~]# ls -l /etc/ |grep -w "cron"
drwx------ 2 root root 4096 Jul 8 2013 cron.d 系統自動按期須要作的任務
drwxr-xr-x 2 root root 4096 Jul 8 2013 cron.daily 天天執行一次的job
-rw-r--r-- 1 root root 0 Jul 8 2013 cron.deny 用於控制不讓哪些用戶使用Crontab的功能
drwxr-xr-x 2 root root 4096 Jul 8 2013 cron.hourly 每一個小時執行一次的job
drwxr-xr-x 2 root root 4096 Jul 8 2013 cron.monthly 每個月執行一次的job
drwxr-xr-x 2 root root 4096 Jul 8 2013 cron.weekly 每一個星期執行一次的joboracle
crontab文件格式
* * * * * command
minute hour day month week command
分 時 天 月 星期 命令
* */1 * * * ntpdate 0.asia.pool.ntp.orgurl
特殊字符
星號(*):表明每的意思,例如month字段若是是星號,則表示每個月都執行該命令操做。
逗號(,):表示分隔時段的意思,例如,「1,3,5,7,9」。
中槓(-):表示一個時間範圍,例如「2-6」表示「2,3,4,5,6」。
正斜線(/):能夠用正斜線指定時間的間隔頻率,例如「0-23/2」表示每兩小時執行一次。同時正斜線能夠和星號一塊兒使用,例如*/10,若是用在minute字段,表示每十分鐘執行一次。rest
crond開機自動啓動
查看
[root@rac1 ~]# chkconfig --list crond
crond 0:off 1:off 2:on 3:on 4:on 5:on 6:off
開啓
[root@rac1 ~]# chkconfig --level 35 crond oncrontab
示例
* * * * * /home/test.sh ##每1分鐘執行test.sh腳本
30 3,12 * * * /home/test.sh ##每個月天天凌晨3點30分和中午12點20分執行test.sh腳本
30 3,12 * * * /home/test.sh ##每個月天天凌晨3點30分和中午12點20分執行test.sh腳本
30 */6 * * * /home/test.sh ##每個月天天每隔6小時的每30分鐘執行test.sh腳本
30 8-18/2 * * * /etc/init.d/network restart ##每個月天天早上8點到下午18點每隔2小時的每30分鐘執行test.sh腳本
30 21 * * * /etc/init.d/network restart ##每個月天天晚上21點30分執行test.sh腳本
45 4 1,10,22 * * /etc/init.d/network restart ##每個月1號、10號、22號凌晨4點45分執行test.sh腳本
10 1 * 8 6,0 /etc/init.d/network restart ##8月份周1、週日凌晨1點10分執行test.sh腳本
00 */1 * * * /etc/init.d/network restart ##每個月天天每小時整點執行test.sh腳本it