I'm having trouble making a python script run via cronjob.
I can run the python script (it's supposed to connect to a database, pull a few records, save that to a csv, then email it) manually just fine. However, I can't get it to run. It's supposed to run every minute, for testing.
Here's the line in the crontab -e:
* * * * * /usr/bin/python /appl/belo_monthly/belo_monthly.py > /appl/belo_monthly/results.log
I've used chmod -x
on the file. I've also tried to write out the print
lines of the file to a log. None are working - won't even create .log file.
The python file has #!/usr/bin/python
at the very top.
What I tried:
I looked it up here, and found this: Python script not running as cronjob
Using that as a reference:
- Yup, cron daemon is running.
pidof cron
returns a value. - A lot of other services depend on this, so I can't restart it.
sudo tail -f /var/log/syslog
gets me the following:
Mar 31 10:21:01 ip-XX-XXX-XXX-XX CRON[30223]: (ubuntu) CMD (/usr/bin/python /appl/belo_monthly/belo_monthly.py > /appl/belo_monthly/results.log)
And it adds another line like that a minute later.
- Finally, I tried this:
sudo strace -f -p pidof cron
. Which returned this:
execve("/bin/sh", ["/bin/sh", "-c", "/usr/bin/python /appl/belo_month"...], [/* 6 vars */]) = 0
And then some garbled mess of text later, this:
open("/appl/belo_monthly/results.log", O_WRONLY|O_CREAT|O_TRUNC, 0666) = -1 EACCES (Permission denied)
write(2, "/bin/sh: 1: ", 12) = 12
write(2, "cannot create /appl/belo_monthly"..., 63) = 63
write(2, "\n", 1) = 1
exit_group(2)
So I'm thinking, it can't create a log. But what about the python script? What happened?
#!/usr/bin/python
at the top of my python files.