title: Running a python script for django via cron
body: <p>I have a python script that connects to an external host, fetches some data, and populates a Django database with the data. The python script that populates the database uses these lines to setup the django environment:</p>
  
  <pre><code>path = os.path.normpath(os.path.join(os.getcwd(), '..'))
  sys.path.append(path)
  from django.core.management import setup_environ
  import settings
  setup_environ(settings)
  </code></pre>
  
  <p>Then I have a shell script that actually runs the python script:</p>
  
  <pre><code>export PYTHONPATH=$PYTHONPATH:/home/django/project_dir/
  cd ~/project_dir/scripts/
  ~/virtualenv/bin/python my_script.py
  </code></pre>
  
  <p>And then my cron config, which is placed in /etc/cron.d/</p>
  
  <pre><code>0 1 * * * django ~/project_dir/scripts/my_script.sh &gt; /var/log/django_cron.log
  </code></pre>
  
  <p>Note that the django project has it's own user and virtual environment.</p>
  
  <p>The shell script runs fine when I am logged in as the django user. But the cron won't run! I get no errors in the log file. I'm sure it's something very simple, but I just don't see it...</p>