On Thu, Mar 10, 2011 at 12:49 PM, Tom Evans <tevans...@googlemail.com> wrote:
> On Thu, Mar 10, 2011 at 5:42 PM, Sells, Fred
> <fred.se...@adventistcare.org> wrote:
>> I'm sure the solution is out there somewhere, but my google search is
>> giving me too many false positives.
>>
>> I have a stand along python program that will be run as a cron job and I
>> don't know how to launch it so it picks up the django settings, etc.
>>
>> I can run it like this
>>
>>>python manage.py shell
>>>>>import mymodule
>>>>>mymodule.execute()
>>
>> But I would like to run it like
>>
>>>python mymodule.py
>>
>> I really don't want to set the DJANGO_SETTINGS_MODULE as a system
>> environment variable since I have other django webapps I debug on this
>> box, but perhaps I just don't grasp the concept here.  I apologize for
>> asking something that I'm sure has been covered, I just could not find
>> it.
>>
>> I'm currently using django 1.2.4 and Python 2.4 but could upgrade both
>> if that's the correct solution.
>>
>
> The easiest way is to wrap your python script in a shell script. This
> would be necessary* if using virtualenv. Mine look like this (from
> rote, so may be wrong):
>
>  #!/bin/sh
>  . /path/to/django/install/my-venv-name/bin/activate
>  DJANGO_SETTINGS_MODULE=myproj.settings
>  export DJANGO_SETTINGS_MODULE
>  # virtualenv activate ensures we get right python
>  python /path/to/django/install/myproj/manage.py foobar "$*"
>
>
> You can then put this directly into cron:
>
> @daily /path/to/wrapper.sh "bar" "quuz wibble"
>
> Cheers
>
> Tom
>
> * well, easier. Maybe not necessary

Another approach is to write your script as a django manage.py
command.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to