I've been trying to get this to work for DAYS. Its doing my head in because everything i search suggests this work.
The process is Cron executes bash which executes python
I open and edit the cron with:
sudo crontab -e
Inside it looks like this:
* * * * * /home/pi/cron_bash.sh >> /home/pi/out.txt 2>&1
This then feeds through to the bash file which looks like this:
#!/bin/sh cd "$(/home/pi "$0")"; CWD="$(pwd)" echo $CWD python /home/pi/cron_log.py
The python script is very simple (primairly for debugging process, i'm planning on changing to a script that executes selenium when i've found the issue)-just prints the datetime to a file:
from datetime import datetime dateTimeObj = datetime.now() dateStr = dateTimeObj.strftime("%B the %d of %Y is %A at %I:%M %p") with open('cronlog.txt', 'a') as file: file.write(dateStr)
The problem i have is that the output file (cronlog.txt) doesn't get changed. If i check the out.txt file which should be displaying the log i get this:
/home/pi/cron_bash.sh: 2: /home/pi/cron_bash.sh: /home/pi: Permission denied /root
Can anyone help? I don't understand how it could be a permission issue if i'm going through sudo cron, but then again i am a beginner with pi/cron.