--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