tags:

views:

338

answers:

2

I am trying to develop a site using pinax. To index the models using djapian I've been trying to run "manage.py index" as a cron job but keep getting a pinax error. "Error: No module named notification". However the task executes correctly when i run it from the shell. My crontab definition is as follows:

SHELL=/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/mypath/test_project

# m h dom mon dow user  command
*/1 *   * * *   root    python /root/mypath/test_project/manage.py index >>/tmp/backup.log 2>&1

Can anyone explain why I am receiving this error?

+6  A: 

Your error is probably because you don't have your PYTHONPATH set properly, especially to include the path to the "notification" module. You also need to set the DJANGO_SETTINGS_MODULE path, if it isn't already set in your environment.

Here's a shell script I use to wrap my own django based cron task:

#!/bin/sh
DJANGO_SETTINGS_MODULE=mysettings
export DJANGO_SETTINGS_MODULE

PYTHONPATH=/path/to/python_libs:/path/to/my_django_apps
export PYTHONPATH

/path/to/python /path/to/my_django_script
ars
ars thanks for the reply. Guided by your suggestion I have fixed the problem.
kartikq
A: 

As ars alluded to, cron runs with an entirely different set of environment variables than you do. The easiest way to fix that is to use a script similar to what he posted.

Xiong Chiamiov