Running python script using cron

Running python script using cron

Posted by: patrickbeeson
Posted on: 2008-03-04 04:36:00

'm trying to use a cron job to run a python script that updates feeds
on an aggregator site I'm building. But I'm getting trackback errors
telling me it can't import the module feedparser. Here's the error:

Traceback (most recent call last):
File "/path/to/script/update_feeds.py", line 10, in ?
import feedparser
ImportError: No module named feedparser

And here is the cron:

export PYTHONPATH=/path/to/python2.3/site-packages:/path/to/django/app
export DJANGO_SETTINGS_MODULE=myproject.settings
1 * * * * /usr/bin/python /path/to/script/update_feeds.py

Any suggestions on what I'm doing wrong?

Re: Running python script using cron

Posted by: patricktan
Posted on: 2008-03-04 07:04:00

In reply to:

File "/path/to/script/update_feeds.py", line 10, in ?
import feedparser
ImportError: No module named feedparser


As the error indicates, you are failed to import a module. Is the module properly installed or imported?

Re: Running python script using cron

Posted by: patrickbeeson
Posted on: 2008-03-04 07:06:00

I'm not sure how to do this in the cron job.

I can run the script fine from the command line.

Re: Running python script using cron

Posted by: scjessey
Posted on: 2008-03-04 07:07:00

In reply to:

you are failed


That sounds a bit harsh LOL.



-- si-blog --

Re: Running python script using cron

Posted by: patrickbeeson
Posted on: 2008-03-04 08:16:00

Do you have any advice on this issue?

Re: Running python script using cron

Posted by: scjessey
Posted on: 2008-03-04 12:19:00

In reply to:

Do you have any advice on this issue?


Nope. I just thought the comment came out a bit funny, that's all.



-- si-blog --

Re: Running python script using cron

Posted by: patricktan
Posted on: 2008-03-04 23:12:00

Sorry about my English. It should be "you failed to". I'll be more careful next time.

Re: Running python script using cron

Posted by: patricktan
Posted on: 2008-03-04 23:13:00

In reply to:

I can run the script fine from the command line.


What is the command you used to run your script from command line?

Re: Running python script using cron

Posted by: patrickbeeson
Posted on: 2008-03-05 07:00:00

$ python /home/user/path/to/script/update_feeds.py

Re: Running python script using cron

Posted by: patrickbeeson
Posted on: 2008-03-05 12:47:00

I solved the issue this morning. Here is a link to my post explaining how I did it: http://groups.google.com/group/django-users/msg/aad5a64db2668d3f

Tags: cron jobpython scriptusr bindjangopython2cron jobpython scriptusr bindjangopython2