WebFaction
Community site: login faq

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 !

asked 01 Apr '13, 17:47

PepperoniPizza
1337
accept rate: 0%

Try adding all of the environment variables and the last line within a single executable script, than invoke that script with cron.

(02 Apr '13, 00:50) johns

Not knowing much about your environment (eg, are you using virtualenv?), my approach would be to get the management command running from within a bash script. Start with the first two lines of the crontab that you've listed, then the last one. See if that works, and debug it from there.

Also, I'd recommend logging the output of your cron scripts, eg:

0 0 * * * ~/do_stuff.sh >> $HOME/logs/cron.log 2>&1
permanent link

answered 01 Apr '13, 20:56

ebrelsford
313
accept rate: 0%

Hi, I'm not using virtualenv, I also tried running it from a bash script, but I will try adding the first two lines and will redirect my output to a log, thanks.

(02 Apr '13, 12:21) PepperoniPizza

I appended the >> $HOME/logs/crong.log 2>&1 to my cron, but I'm not getting any output on that location

(04 Apr '13, 14:45) PepperoniPizza

Try using $HOME/logs/user/cron.log instead. ($HOME/logs is not writable)

(04 Apr '13, 15:07) seanf

That created the log, but it's an empty file, nothing in it.

(06 Apr '13, 18:15) PepperoniPizza

In the comments of this post are commands to temporarily modify your environment to match cron's environment. Have you tried this yet?:

cd $HOME
unset $(env | awk -F= '/^\w/ {print $1}' | xargs)
export USER=$(/usr/bin/whoami)
export SHELL=/bin/sh
export PATH=/usr/bin:/bin
export PWD=/home/$USER
export SHLVL=1
export HOME=/home/$USER
export LOGNAME=$USER
~/do_stuff.sh

If this doesn't run, then the problem is related to the environment, and you will want to set any appropriate environment variables within the ~/do_stuff.sh script. Hope that helps!

(06 Apr '13, 19:18) ryans ♦♦

@ryans it works, I can run the script, but still cron won't run my .sh script. This is really annoying.

(02 May '13, 12:27) PepperoniPizza

Please open a support ticket, and we'll look into it.

(02 May '13, 12:43) seanf
showing 5 of 7 show 2 more comments
Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:

×909
×81
×50
×14

question asked: 01 Apr '13, 17:47

question was seen: 3,184 times

last updated: 02 May '13, 12:43

WEBFACTION
REACH US
SUPPORT
AFFILIATE PROGRAM
LEGAL
© COPYRIGHT 2003-2019 SWARMA LIMITED - WEBFACTION IS A SERVICE OF SWARMA LIMITED
REGISTERED IN ENGLAND AND WALES 5729350 - VAT REGISTRATION NUMBER 877397162
5TH FLOOR, THE OLD VINYL FACTORY, HAYES, UB3 1HA, UNITED KINGDOM