how to make cron works

已查看 28 次
跳至第一个未读帖子

kevi...@gmail.com

未读,
2008年2月15日 00:32:412008/2/15
收件人 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

未读,
2008年2月15日 00:46:302008/2/15
收件人 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

未读,
2008年2月15日 01:07:462008/2/15
收件人 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

未读,
2008年2月15日 01:17:042008/2/15
收件人 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

未读,
2008年2月15日 01:25:502008/2/15
收件人 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

未读,
2008年2月15日 01:29:312008/2/15
收件人 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

未读,
2008年2月15日 10:27:302008/2/15
收件人 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:

回复全部
回复作者
转发
0 个新帖子