Search code examples
linuxdjangocronwebfaction

Crontab Django script on webfactional


I need someone to figure out why is my cron job not working on webfactional. There is a couple of similar questions but my case is particular I think since I could not make it work yet. So I have this script on python which can be run python2.7 manage.py my_script_name. My project on webfactional has the following structure:

home/my_username/webapps/bip/bip/
----apps/
----media/
----static/
----project/
--------manage.py
--------settings.py

My crontab -e looks like this:

PYTHONPATH=/home/my_username/webapps/bip/lib:/home/my_username/webapps/bip/lib/python2.7:/home/my_username/webapps/bip/bip:/home/my_username/webapps/bip/bip/project
DJANGO_SETTINGS_MODULE=project.settings

6,26,46 * * * * ~/webapps/django/apache2/bin/start
3,23,43 * * * * ~/webapps/bip/apache2/bin/start
0 0 * * * /usr/local/bin/python2.7 ~/webapps/bip/bip/project/manage.py my_script_name

Of course my problem is that cron does not run my script. I know that crontab uses a limited ENV, so this might be the problem. Any help is appreciated.

Thanks !


Solution

  • The way I got it working was the following:

    make a bash file that includes the following:

    PYTHONPATH=/home/my_username/webapps/bip/lib:/home/my_username/webapps/bip/lib/python2.7:/home/my_username/webapps/bip/bip:/home/my_username/webapps/bip/bip/project
    DJANGO_SETTINGS_MODULE=project.settings
    
    /usr/local/bin/python2.7 ~/webapps/bip/bip/project/manage.py my_script_name &>> ~/logs/user/my_script_name
    

    and on the crontab the following:

    0 0 * * * cd ~/bin/;./my_bash_file.sh >> $HOME/logs/user/cron.log 2>&1