In order to detect a fault that would happen in my cron job, I set an other cron job to check the previous log issued by the crontab:
def check_last_cron():
with open('/home/pi/Desktop/cron_output.log') as f:
txt = f.read()
f.close()
if 'Traceback' in txt:
print('Traceback detected')
send_to_phone(txt)
else:
print('no Traceback detected')
When run manually, everything goes well:
- the script reads
- detects the word "Traceback"
- sends me the log
Crontab:
*/5 * * * * python3 /home/pi/Desktop/initialize.py > /home/pi/Desktop/cron_output.log 2>&1
*/5 * * * * python3 /home/pi/Desktop/checker.py > /home/pi/Desktop/log.log 2>&1
But when run with the crontab, the log read is empty. What am I missing ?