1 安装

  1. yum install crontabs

2 启停服务

  1. systemctl enable crond
  2. systemctl start crond

3 配置定时规则

3.1 文件配置

  1. vim /etc/crontab
  1. SHELL=/bin/bash
  2. PATH=/sbin:/bin:/usr/sbin:/usr/bin
  3. MAILTO=root
  4. # For details see man 4 crontabs
  5. # Example of job definition:
  6. # .---------------- minute (0 - 59)
  7. # | .------------- hour (0 - 23)
  8. # | | .---------- day of month (1 - 31)
  9. # | | | .------- month (1 - 12) OR jan,feb,mar,apr ...
  10. # | | | | .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat
  11. # | | | | |
  12. # * * * * * user-name command to be executed
  13. 0,5,10,15,20,25,30,35,40,45,50,55 * * * * root /root/xxx/xxx/xxx.sh

按照文件配置启动定时任务

  1. crontab /etc/crontab

3.2 -e命令直接新增一个定时任务

4 查看定时任务

  1. crontab [ -u user ] { -l | -r | -e }
  2. -e : 执行文字编辑器来设定时程表,内定的文字编辑器是 VI,如果你想用别的文字编辑器,则请先设定 VISUAL 环境变数来指定使用那个文字编辑器(比如说 setenv VISUAL joe)
  3. -r : 删除目前的时程表
  4. -l : 列出目前的时程表