如果脚本中会有涉及读取配置文件或者读写文件的动作,一般定时任务都会执行失败。

修改HOME目录

在/etc/cron.d 目录下新建一个文件,命名为什么都可以

1
2
3
4
5
SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root
HOME=/usr/lib64/nagios/plugins/ # python 脚本路径
*/1 * * * * root python check_dns.py # python 脚本

参考资料

 上一篇

Linux