本文环境:centos7
查看是否启动
systemctl status crond
编写测试脚本crontest.sh
#!/bin/bash
/usr/bin/echo 123 >> /opt/crontest.txt
此处需要修改脚本权限,否则无法执行
chmod 777 crontest.sh
设置每一分钟执行一次
新建mycron.cron文件,内容:
* * * * * /usr/bin/sh /opt/crontest.sh
- 执行任务
crontab mycron.cron
- 查看所有任务
crontab -l
- 结束所有任务
crontab -r
打印输出日志
* * * * * /usr/bin/sh /opt/crontest.sh > /opt/test.log 2>&1 &