3

I have a shell script, thus:

export PYTHONPATH=/usr/local/lib/python
cd /home/skip/workspace/UAM
for file in *.txt
do
    echo $file >>log.fil
    /usr/bin/python push.py -s $file
done
return 0

It runs properly from command line. prints each filename to the log file and runs the python push.py command as expected. (It creates a directory and populates it.)

But when I try to run it from cron with this crontab:

3 * * * * /home/skip/workspace/UAM/RunAllTest.sh 

I am seeing entries in the log file, but push.py is not run properly. (the directory is not created or populated.)

Any assistance would be welcome.

2 Answers 2

3

Check that push.py doesn't need any environment variables that may not be set in crontab context. If it is a user crontab (not a root cron) then it will be executed as if the same user executed that line, but not necessarily into the same environment (like aliases and Path set on initialization files).

Sign up to request clarification or add additional context in comments.

1 Comment

Fantastic. That is very helpful. I don't think it is my actual problem, but it inspired me to dig a bit deeper. I will report more later. (Basically if I strip most of what "push.py" is supposed to be doing out, then the cron process works. It's USELESS, but it works.)
1

Got it. Thanks to the kind assistance of licorna.

What was happening is my "push.py" script was calling another program (pybot aka robot framework) without specifying a fully qualified path.

I changed that from "pybot" to /usr/local/bin/pybot" and all is working.

1 Comment

You might see if you're using sh or bash for your script (you don't include the first line). Bash may include the proper path for you. I would accept @licorna's answer, since it includes "Path set on initialization files"

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.