Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 990425
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T05:56:46+00:00 2026-05-16T05:56:46+00:00

I have a python script that connects to an external host, fetches some data,

  • 0

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:

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)

Then I have a shell script that actually runs the python script:

export PYTHONPATH=$PYTHONPATH:/home/django/project_dir/
cd ~/project_dir/scripts/
~/virtualenv/bin/python my_script.py

And then my cron config, which is placed in /etc/cron.d/

0 1 * * * django ~/project_dir/scripts/my_script.sh > /var/log/django_cron.log

Note that the django project has it’s own user and virtual environment.

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…

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T05:56:47+00:00Added an answer on May 16, 2026 at 5:56 am

    The problem was actually that I have an environment variable to tell django if it is running in development or production. Crontab doesn’t execute the .bashrc file where I export this variable so that had to be added to my shell script:

    export FLAVOR=live
    export PYTHONPATH=$PYTHONPATH:/home/django/project_dir/
    cd ~/project_dir/scripts/
    ~/virtualenv/bin/python my_script.py
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Python command line script that connects to a database, generates files
I have a Python script that is using some closed-box Python functions (i.e. I
I have a python script that runs on a cron job. The script uses
I have a Python script that uses built-in modules but also imports a number
I have a python script that uses threads and makes lots of HTTP requests.
I have a python script that uses plt.show() as it's last instruction. When it
I have a python script that connects to a local MySQL db. I know
I have a python script that makes about ten INSERTs into a MySQL database.
I have a python script using imaplib that connects to a gmail account and
I have an isolated python script that simply captures data from Twitter's streaming API

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.