Reputation: 1857
I am trying to set a cron task for running a python script everyday at a specific time. Here is my crontab -e
:
53 16 * * * python /code/4dlife/pythonscript.py
and I set this at 16:52 and waited and watched but nothing came up on the terminal. I checked nano CRON /var/log/syslog
but it was empty.
What am I doing wrong? Can I see the script running on the same terminal as I have open? If not, where else can I see the output? BUT FIRST, I need to make it work.
Note:
#!/usr/bin/env python
on top of my python scriptUpvotes: 0
Views: 951
Reputation: 57
Use the exact path of your python executable in your crontab:
53 16 * * * /usr/bin/python /code/4dlife/pythonscript.py
This way you can be certain that your crontab knows where to find python.
A way to debug scripts that run automatically is writing to syslog :
import syslog
syslog.syslog(syslog.LOG_ERR, "---SCRIPT START---")
Upvotes: 1
Reputation: 708
I used to have problems with Python in cron, but they were solved as I began to use virtualenv/virtualenvwrapper + pyenv .
Since them, I have used cron running the command with Python's full path, like
53 16 * * * /usr/bin/python /code/4dlife/pythonscript.py
. To get the full path, run in the shell
$ which python
and use the path as I showed.
The difference is that, in my case, the Python binary is located on a specific folder (~/.virtualenv/<env-name>/bin/python
).
Upvotes: 0
Reputation: 1
Does your script work correctly in the terminal? I mean, when you type :
python /code/4dlife/pythonscript.py
Does the result appear?
Upvotes: 0