1 未启动crontab
service crond restart 重新启动
service crond status 查看状态
2 使用crontab设置任务时一定要写全路径:
如: /usr/bin/python3 test.py
而如果写 python3 test.py
或者
进入编辑界面后添加环境变量设置,以及指定的任务:
SHELL=/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
00 03 * * * . /etc/profile; /bin/sh /mnt/test1.sh
01 03 * * * . /etc/profile; /bin/sh /mnt/test2.sh
注意一定要添加“ . /etc/profile;” ,这句用于将环境变量include进当前脚本的执行环境!
否则你就会遇到一个经典问题:
手动输入:
/bin/sh /mnt/test1.sh
可以执行,但放在crontab里就总是不起作用。
通过指令查询任务是否开始运行
ps -aux|grep python3
杀掉所有python3 任务
ps -ef|grep python3|grep -v grep|cut -c 9-15|xargs kill -9
以下这篇总结得不错
https://blog.csdn.net/tianqishu11/article/details/78717249