[root@localhost ~]# cat /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
[root@localhost ~]# crontab -l
命令错误 crond没启动或格式错误等都会造成计划任务不执行
[root@localhost ~]# crontab -l
# 每日8:15分给1.txt追加1
15 8 * * * echo "1" >> 1.txt
# 每隔8小时执行
* */8 * * * echo "1" >> 1.txt 2>>2.txt
# 每天的1,12,18时执行
* 1,12,18 * * * echo "1" >> 1.txt
# 每天的9:30到18:30执行
* 9-19 * * * echo "123" >> 1.txt
# 每周日的5:00执行
* 5 * * 0 echo "123" >> 1.txt
要保证服务是启动状态 systemctl start crond.service