Skip to content Skip to sidebar Skip to footer

Crontab Issues Running Python

I'm trying to get cron to run this command every 10 minutes; (In /home/pi/myst-myst/ DIR) python myst.py `./monitor.sh` I've tried pretty much everything to get it to work but cro

Solution 1:

I've had problems calling both python and perl directly from cron. For perl it boiled down to LIBPATH defaulting to something insufficient.

I'd suggest wrapping your commands in a shell script and adding "set -x" to trace through the problem

#!/bin/shset -x
export PYTHONPATH=/my/python/modules:$PYTHONPATH
/usr/bin/python /home/pi/myst-myst/myst.py $(/home/pi/myst-myst/monitor.sh)

Call it directly to make sure it works, and then try calling via cron. Make sure to redirect both stdout and stderr to capture any error messages

 */10 * * * * /home/pi/myscript.sh > /home/pi/stdout 2> /home/pi/stderr

Solution 2:

You could do something like

*/10 * * * * cd /home/pi/myst-myst/;/usr/bin/python /home/pi/myst-myst/myst.py $(./monitor.sh)

to change working directory before running the command.

Edit: replaced backticks

Solution 3:

Does your script rely on any environment variables, such as PYTHONPATH? If so, the environment will be missing when invoked by cron.

You can try:

*/1 * * * * PYTHONPATH=/my/python/modules/ /usr/bin/python /home/pi/myst-myst/myst.py`./monitor.sh`

Solution 4:

Try this way:

 */1 * * * * /home/pi/myst-myst/myst.py`./monitor.sh`

And add the following in myst.py

#!/usr/bin/env python

Post a Comment for "Crontab Issues Running Python"