Hi, I used ubuntu crontab to exec python script in my project.
1. In crontab, you can do like this:
DJANGO_SETTINGS_MODULE=divo3.settings
PYTHONPATH=/root/deploy
# m h dom mon dow command
50 * * * * python /root/deploy/divo3/job.py
2. The job.py file must put in the root dir of django project, its
content like this:
#coding=utf-8
from apps.check.views.job import do_check_job
from apps.board.views.job import do_board_job
from apps.core.views.job import do_core_job
from apps.xf.views.job import do_xf_job
from apps.utils.log import log_error
if __name__ == "__main__":
do_core_job()
do_board_job()
do_check_job()
do_xf_job()
#EOP
On 9月25日, 上午1时15分, Matt McCants <[email protected]> wrote:
> I knew this would happen as soon as I hit submit to make a fool of
> myself.
>
> So I tried to use:
> manage.py custom_command_name --pythonpath='/path/to/my/project'
>
> but that had not worked either. The real path to the project is:
>
> /home/webdev/django/fls
>
> but I failed to put in:
>
> manage.py custom_command_name --pythonpath='/home/webdev/django'
>
> seems to have done the trick. As I said, I'm fairly new to Django and
> Python. I understand why I was wrong. Thanks for reading anyway!
>
> Matt
>
>
>
>
>
>
>
> On Thu, 2009-09-24 at 13:05 -0400, Matt McCants wrote:
> > Greetings all,
>
> > I'm having an issue running a custom command as a cron. Most resources
> > I've read have said that you can run your command from cron by simply
> > using the following syntax:
>
> > python manage.py custom_command_name
>
> > Frustratingly, that does not work for me. It results in "Unknown
> > command: 'custom_command_name'" Further attempts such as:
>
> > /usr/bin/python /path/to/my/project/manage.py custom_command_name
>
> > or any variation fail. If I run:
>
> > python /path/to/my/project/manage.py help
>
> > It executes, but my custom command does not show up.
>
> > The custom command works fine when I call it from within the project
> > directory.
>
> > I suspect it has something to do with PythonPaths. I'm pretty new to
> > both Django and Python, so any help is greatly appreciated.
>
> > Thanks,
> > Matt McCants
>
> > This message is confidential, intended only for the named recipient(s) and
> > may contain information that is privileged or exempt from disclosure under
> > law. If you are not the intended recipient(s), you are notified that the
> > dissemination, distribution, or copying of this message is strictly
> > prohibited, and that this message should be deleted from your system. The
> > Free Lance-Star Publishing Company accepts no liability for the content of
> > this message, or for the consequences of any actions taken on the basis of
> > the information provided. If you receive this message in error, or are not
> > the named recipient(s), please notify the sender and delete the document
> > from your computer.
>
> This message is confidential, intended only for the named recipient(s) and
> may contain information that is privileged or exempt from disclosure under
> law. If you are not the intended recipient(s), you are notified that the
> dissemination, distribution, or copying of this message is strictly
> prohibited, and that this message should be deleted from your system. The
> Free Lance-Star Publishing Company accepts no liability for the content of
> this message, or for the consequences of any actions taken on the basis of
> the information provided. If you receive this message in error, or are not
> the named recipient(s), please notify the sender and delete the document from
> your computer.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---