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?

2
  • ehat exactly means "won't execute it properly"? Is there anything in the logs? Commented Mar 11, 2013 at 8:48
  • I can't find anything in the logs that's relevant.. Commented Mar 11, 2013 at 9:05

4 Answers 4

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
Sign up to request clarification or add additional context in comments.

Comments

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

3 Comments

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
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.
I've modified it to match yours and still doesn't seem to be working.
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`

1 Comment

that don't work because the current directory of a cron is not the one of monitor.sh
0

Try this way:

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

And add the following in myst.py

#!/usr/bin/env python

1 Comment

that don't work because the current directory of a cron is not the one of monitor.sh

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.