I hava executable a.py file worked fine when running in CLI. But after I wrote a a.sh script /root/a.py >> /root/a.log
and start a crontab * * * * * /bin/sh /root/a.sh
, it worked fine except no outputting in the log file.
The logging part of a.py was configured as follows:
DATE_FORMAT = '%a, %d %b %Y %H:%M:%S'
LOG_FILE = 'log'
RESULT_LOG_FILE = 'result.log'
LOG_FORMAT = '[%(asctime)s] [%(filename)s:%(lineno)d] [%(levelname)s] [%(threadName)s] [%(process)d] %(message)s'
logging.basicConfig(format=LOG_FORMAT, datefmt=DATE_FORMAT, level=logging.INFO, filename=LOG_FILE)
logging.error('ERROR')
I have tried to add /usr/local/bin/python
in front of /root/a.py
in a.sh but it did not work. I have no idea why this happened.