One, create a shell script
vim /data/date/date.sh
#/bin/bash
DATE1=$(date +%F)
cd /data/date
echo $DATE1 >> /data/date/date.log
mkdir $DATE1
Two, grant execution permissions to the script
cd /data/date
chmod u+x date.sh #使脚本具有执行权限
./date.sh #执行脚本
##变绿代表拥有执行权限
Three, linux command to start timing
1. Install and start the corresponding software
yum install -y crond sendmail
systemctl restart crond
systemctl enable crond
systemctl restart sendmail
2. Set timed tasks
crontab -e
或者 vim /etc/crontab
#####
0 0 * * * /data/date/date.sh
分 时 日 月 周(0-6)【用户】 绝对路径脚本
#####
当用户是root时,需省略,否者会出现下图报错
/bin/sh: root: command not found
3. Load the configuration
systemctl reload crond
4. View timed tasks:
crontab -l