1 安装
yum install crontabs
2 启停服务
systemctl enable crond
systemctl start crond
3 配置定时规则
3.1 文件配置
vim /etc/crontab
SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root
# 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
0,5,10,15,20,25,30,35,40,45,50,55 * * * * root /root/xxx/xxx/xxx.sh
按照文件配置启动定时任务
crontab /etc/crontab
3.2 -e命令直接新增一个定时任务
4 查看定时任务
crontab [ -u user ] { -l | -r | -e }
-e : 执行文字编辑器来设定时程表,内定的文字编辑器是 VI,如果你想用别的文字编辑器,则请先设定 VISUAL 环境变数来指定使用那个文字编辑器(比如说 setenv VISUAL joe)
-r : 删除目前的时程表
-l : 列出目前的时程表