0

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 cron won't execute it properly. Here is what I have at the moment;

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

Any help would be much appreciated.

Is there an alternative to crontab I could use? Could I use a bash script to execute python and then use a cron for that bash script?

Hugo
  • 37
  • 1
  • 7

4 Answers4

2

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/sh
set -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
TheDuke
  • 750
  • 1
  • 7
  • 22
1

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

Fredrik Håård
  • 2,856
  • 1
  • 24
  • 32
  • I tried that but it didn't work. Even this doesn't work properly; sudo /usr/bin/python /home/pi/myst-myst/myst.py `/home/pi/myst-myst/monitor.sh` – Hugo Mar 11 '13 at 09:05
  • You probably should add some output to your script (myst.py), but two things I can spot are that the backticks seems to make problems in crontab in my experience and should be replaces by $(command), and that you need the 'cd /home/pi/myst-myst;' part or ./monitor.sh won't work since it won't be in the current directory. – Fredrik Håård Mar 11 '13 at 09:35
  • I've modified it to match yours and still doesn't seem to be working. – Hugo Mar 11 '13 at 09:57
0

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`
shx2
  • 61,779
  • 13
  • 130
  • 153
0

Try this way:

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

And add the following in myst.py

#!/usr/bin/env python
winoi
  • 237
  • 2
  • 4
  • 11