how to make cron works

28 views
Skip to first unread message

kevi...@gmail.com

unread,
Feb 15, 2008, 12:32:41 AM2/15/08
to Django users
i have a python script which works smooth for me in command line.
but now it cannot work in cron job.

path: /home/data
script: test.py
it works as i type : python test.py

now i wirte a shell script as below(test.sh):
cd /home/data
python test.py

so when i run test.sh, it is ok.

but when i set a cron job to run this shell, i always get this error
of cannot import modules, i am sure it is nothing about modules
missing, it only becuse i run it under script.

can somebody help me, thanks!

Malcolm Tredinnick

unread,
Feb 15, 2008, 12:46:30 AM2/15/08
to django...@googlegroups.com

Crontab doens't run with the same environment as you, the user. In
particular the Python path will be different. Listen to the error
message; it's telling you the right thing.

Malcolm

--
Tolkien is hobbit-forming.
http://www.pointy-stick.com/blog/

kevi...@gmail.com

unread,
Feb 15, 2008, 1:07:46 AM2/15/08
to Django users
the error as below:
1. Traceback (most recent call last):
File "feedup.py", line 3, in ?
from django.core.management import setup_environ
ImportError: No module named django.core.management

2. Traceback (most recent call last):
File "mstart", line 13, in ?
import msnlib
ImportError: No module named msnlib


thanks!

On Feb 15, 1:46 pm, Malcolm Tredinnick <malc...@pointy-stick.com>
wrote:
> Tolkien is hobbit-forming.http://www.pointy-stick.com/blog/- Hide quoted text -
>
> - Show quoted text -

Malcolm Tredinnick

unread,
Feb 15, 2008, 1:17:04 AM2/15/08
to django...@googlegroups.com

On Thu, 2008-02-14 at 22:07 -0800, kevi...@gmail.com wrote:
> the error as below:
> 1. Traceback (most recent call last):
> File "feedup.py", line 3, in ?
> from django.core.management import setup_environ
> ImportError: No module named django.core.management
>
> 2. Traceback (most recent call last):
> File "mstart", line 13, in ?
> import msnlib
> ImportError: No module named msnlib

I'm not going to give you a step-by-step way to fix this. As I said in
the original post, it's most like that cron's idea of the Python path
isn't what it needs to be. So look up how to set environment variables
in cron.

Malcolm

--
A clear conscience is usually the sign of a bad memory.
http://www.pointy-stick.com/blog/

kevi...@gmail.com

unread,
Feb 15, 2008, 1:25:50 AM2/15/08
to Django users
thanks! i need to focus on mkaing shell script
works for me
On Feb 15, 2:17 pm, Malcolm Tredinnick <malc...@pointy-stick.com>
wrote:

Amit Ramon

unread,
Feb 15, 2008, 1:29:31 AM2/15/08
to django...@googlegroups.com
As Malcolm pointed before, the problem is most likely with the value of your PYTHONPATH environment variable. Since you're using a shell script, simply set this variable in this script itself, before invoking the python script.

--- Amit

* kevi...@gmail.com <kevi...@gmail.com> [2008-02-14 22:07 -0800]:

Thomas Guettler

unread,
Feb 15, 2008, 10:27:30 AM2/15/08
to django...@googlegroups.com
On unix (at least linux) you can run a script with an empty environment
like this:

env -i path/to/script

This way you can test on the shell what goes wrong.

I do all the set up in .bashrc an and run the cron job like this:

0 * * * . $HOME/.bashrc; $HOME/.../script

HTH,
Thomas

kevi...@gmail.com schrieb:

Reply all
Reply to author
Forward
0 new messages