LinuxQuestions.org
Review your favorite Linux distribution.
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 08-15-2011, 09:43 PM   #1
leavage
LQ Newbie
 
Registered: Dec 2010
Posts: 11

Rep: Reputation: 0
Cron/writing files


I have a python script that writes a file when ran. This program works fine when I run it from command line. So I tried to get it to run as a cron job. But I get an error 'Runtime error: Cannot open Display'.
What my program does is it opens a new file(creates the file), and writes a line of data to this file. Ive checked the permissions and it really seems that I have the correct permissions to do this.
I don't really see why it is failing under cron. Any ideas?
 
Old 08-15-2011, 10:05 PM   #2
jlinkels
Senior Member
 
Registered: Oct 2003
Location: Bonaire
Distribution: Debian Wheezy/Jessie/Sid, Linux Mint DE
Posts: 4,493

Rep: Reputation: 635Reputation: 635Reputation: 635Reputation: 635Reputation: 635Reputation: 635
apparently you are accessing X, is it a GUI program?

Use absolute paths everywhere. Don't assume anything.

Can you post the offending line from your cron file?

Can you post your code?

jlinkels
 
Old 08-17-2011, 01:34 AM   #3
leavage
LQ Newbie
 
Registered: Dec 2010
Posts: 11

Original Poster
Rep: Reputation: 0
I have figured out that the problem is in the X server and the lines of code

import pylab
from pylab import *

Why does python require the X server?
I need pylab because it has the sys.argv commmand.
 
Old 08-17-2011, 03:16 PM   #4
jlinkels
Senior Member
 
Registered: Oct 2003
Location: Bonaire
Distribution: Debian Wheezy/Jessie/Sid, Linux Mint DE
Posts: 4,493

Rep: Reputation: 635Reputation: 635Reputation: 635Reputation: 635Reputation: 635Reputation: 635
pylab is a plotting library, so it is logical it requires X in one or another way.

However, the sys.argv command is not contained in pylab but in sys.

So you would use:
Code:
import sys
sys.argv
You don't need to call from sys import * as long as you use the module name in front of argv, so sys.argv

jlinkels
 
  


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
Strange Cron directories: /var/spool/cron/cron.GfqqGO Woodsman Slackware 4 05-11-2011 03:37 PM
adding a perl script to cron.daily / cron.d to setup a cron job CrontabNewBIE Linux - Software 6 01-14-2008 09:16 AM
cron not working from crontab nor form /etc/cron/cron.d. What did SuSE change? JZL240I-U SUSE / openSUSE 11 01-04-2007 02:57 AM
Writing a cron job and ... tcv Linux - General 9 08-20-2006 05:14 AM
writing to files in C ocularbob Programming 9 02-17-2004 01:06 PM


All times are GMT -5. The time now is 02:12 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