The problem encountered several times, the record about the settlement process.
problem:
At work we often write a python script, and then want to perform regular tasks through, then we will think crontab.
By crontab -e to set crontab
For example: 0 0 * * * python usr / lib64 / nagios / plugins / check_dns.py
Then if the action involves reading the configuration file or script to read and write files have, in general, the timing of the task will not be executed.
the reason:
Because the script is executed, is due to be executed by crontab, his executive directory will become the current user's home directory, if it is root, will be executed in the / root / down.
Solution:
Create a directory under /etc/cron.d task: vim dns-check
SHELL = / bin / bash
the PATH = / sbin: / bin: / usr / sbin: / usr / bin
MAILTO = root
the HOME = / usr / lib64 / Nagios / plugins / # Python script path
* / 1 * * * * root python check_dns.py # python script execution
Thanks for this author https://www.cnblogs.com/terrycy/p/6961339.html