I have a cron job written to root (I'm writing to a log in
/var/log so need root permission). The problem is that sometimes it works, and sometimes it doesn't.
The cron job is simply to call a python script in my home directory, this then does all the hard work.
I set the job to go off in the middle of the night so it doesn't interfere with what I'm doing and so that the API it interacts with is less likely to change (the API is updated throughout the day).
But every morning I check the logs and get the following error:
python3: can't open file '/home/myUser/path/to/the/main.py': [Errno 2] No such file or directory
My response to this is to change the timing on the crontab to a few minutes beyond the time I am checking the logs, wait a few minutes, and the file starts running. The only thing I change is the timing, and suddenly it works.
So I know, for sure, that the file exists.
I've tried a variation of times at night (
30 23 * * *, 01 01 * * *, 10 02 * * *) none have worked, but whenever I set it off for 2 minutes after I check in the morning, it is fine.
Here is the crontab as it currently stands:
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games 01 01 * * * python3 /home/myUser/path/to/the/main.py >> /var/log/thisjobs.log 2>&1
It's also worth mentioning that there is an additional newline after this job (I've heard that it is necessary).
Has anyone seen this before? Is there anything I can try to get this file found without me having to manually change the script each time?
EDIT: here is my
env output for
LANGUAGE=en_GB:en HOME=/root LOGNAME=root PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games LANG=en_GB.UTF-8 SHELL=/bin/sh PWD=/root
Also thought I'd mention that I have tried using the following command (after the timing) to no avail (same error, but only with the
main.py instead of the full path):
cd /home/myUser/path/to/the; python3 main.py