一、安装crontab
yum -y install crontabs #安装
chkconfig crond on #设为开机启动,先要安装chkconfig(yum install -y chkconfig)
systemctl start crond #启动
systemctl stop crond #停止
systemctl status crond #查看服务状态
二、设置任务计划
crontab -ecrontab文件的格式:
minute hour day month weekday username command
-
-
-
-
- /bin/bash /root/dellog.sh(脚本路径)附:crontab规则详细实例1.每天6点执行0 6 * /bin/bash /root/dellog.sh
-
-
-
2.每天6:30执行
30 6 * /bin/bash /root/dellog.sh3.每周二的6:00执行 (0-6是周日到周六)
0 6 2 /bin/bash /root/dellog.sh4.每月2号的6:00执行
0 6 2 /bin/bash /root/dellog.sh5.每天2-6点执行
0 2-6 * /bin/bash /root/dellog.sh6.每天的0-6点每隔2小时执行
0 2/0-6 * /bin/bash /root/dellog.sh7.每天的0-2、3-5 、 6-8 点执行
0 0-2,3-5,6-8 * /bin/bash /root/dellog.sh三、查看计划任务crontab -l
精彩评论