一个简单的定时任务的案例:
1,统一一下目录
[root@VM-0-11-centos ~]# cd ~
[root@VM-0-11-centos ~]# pwd
/root
[root@VM-0-11-centos ~]# touch test1.sh
[root@VM-0-11-centos ~]# vim test1.sh
2,编辑一个定时任务,wq退出
#!/bin/bash
/bin/echo `date` > console.txt
~
~
~
3,添加定时任务,* * * * * sh /root/test1.sh
[root@VM-0-11-centos ~]# crontab -e
*/5 * * * * flock -xn /tmp/stargate.lock -c '/usr/local/qcloud/stargate/admin/start.sh > /dev/null 2>&1 &'
* * * * * sh /root/test1.sh
[root@VM-0-11-centos ~]# vim console.txt
4, 检查console.txt文件,是否每分钟更新时间
Fri Feb 19 11:50:01 CST 2021
~
~
~