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