LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 03-07-2009, 11:27 PM   #1
terminally.confused
LQ Newbie
 
Registered: Mar 2009
Location: Dunedin, NZ
Distribution: Kubuntu Intrepid
Posts: 3

Rep: Reputation: 0
Unable to run Python script with cron


Hi,

Have a Python script I want to run as a cron task but have been unable to get it working.
The script is called rsscollect.2 and it grabs headlines from a news website's rss feed and emails them via gmail. It works fine from the terminal but I can't run it via crontab.
The script is stored in my documents folder.
The output of crontab -l is
Code:
blairm@orpheus:~/Documents$ crontab -l
PATH=/usr/sbin:/usr/bin:/sbin:/bin
* * * * * /home/blairm/Documents/rsscollect2.py
blairm@orpheus:~/Documents$
Inserted the PATH line at the top on the advice of an Ubuntu tutorial.
Not sure whether it's relevant (apologies, very new to scripts and cron) but this is the script I'm trying to run:

Code:
#! /usr/bin/env python

import urllib
import sys
import xml.dom.minidom

#The url of the feed
address = 'http://www.stuff.co.nz/rss/'

#Our actual xml document
f = open('alerttest.txt',  'w')

document = xml.dom.minidom.parse(urllib.urlopen(address))
for item in document.getElementsByTagName('item'):
    title = item.getElementsByTagName('title')[0].firstChild.data
    link = item.getElementsByTagName('link')[0].firstChild.data
    description = item.getElementsByTagName('description')[0].firstChild.data
    
    print>>f,  '''<a href="%s">%s</a> (%s)''' % (link.encode('UTF8', 'replace'),
                                            title.encode('UTF8','replace'),
                                            description.encode('UTF8','replace'))

f.close()
import smtplib

# from http://stackoverflow.com/questions/399129/failing-to-send-email-with-the-python-example
FROMADDR = "oh.yeah?@gmail.com"
LOGIN    = FROMADDR
PASSWORD = "PASSWORD"
TOADDRS  = ["oh.yeah?@xtra.co.nz"]
SUBJECT  = "Test alert"

msg = ("From: %s\r\nTo: %s\r\nSubject: %s\r\n\r\n"
       % (FROMADDR, ", ".join(TOADDRS), SUBJECT) )
msg += open('alerttest.txt', 'r').read()

server = smtplib.SMTP('smtp.gmail.com', 587)
server.set_debuglevel(1)
server.ehlo()
server.starttls()
server.login(LOGIN, PASSWORD)
server.sendmail(FROMADDR, TOADDRS, msg)
server.quit()
Any advice on where I'm going wrong would be gratefully received.

Blair

Last edited by Tinkster; 03-08-2009 at 03:36 PM. Reason: credentials removed
 
Old 03-08-2009, 01:04 AM   #2
mesiol
Member
 
Registered: Nov 2008
Location: Lower Saxony, Germany
Distribution: CentOS, RHEL, Solaris 10, AIX, HP-UX
Posts: 731

Rep: Reputation: 137Reputation: 137
Hi,

try to set full path for python executable.
does it work?
 
Old 03-08-2009, 01:52 AM   #3
terminally.confused
LQ Newbie
 
Registered: Mar 2009
Location: Dunedin, NZ
Distribution: Kubuntu Intrepid
Posts: 3

Original Poster
Rep: Reputation: 0
Thanks Mesiol,

What do you mean by full path? I thought I had set it but would not be surprised if I was mistaken; my knowledge of linux is scant.

The script is in the documents section of blairm in the home directory.

What more do I need to specify?

Thanks,

Blair
 
Old 03-08-2009, 03:06 PM   #4
terminally.confused
LQ Newbie
 
Registered: Mar 2009
Location: Dunedin, NZ
Distribution: Kubuntu Intrepid
Posts: 3

Original Poster
Rep: Reputation: 0
Okay, sorted now: adding python to the path seemed to do the trick.

Blair
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Script not being run in cron.daily hazmatt20 Linux - General 10 10-12-2008 09:24 PM
can run script from my user but not with cron beeblequix Linux - Enterprise 2 04-13-2007 11:22 AM
FTP Script will not run from Cron grhansen Programming 12 01-13-2006 05:13 AM
unable to run cron job fahad26 Linux - General 3 06-30-2005 02:51 AM
can't get cron to run my script. dr_zayus69 Linux - Software 6 04-12-2005 07:34 PM


All times are GMT -5. The time now is 12:44 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration