LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Debian
User Name
Password
Debian This forum is for the discussion of Debian Linux.

Notices


Reply
  Search this Thread
Old 08-02-2006, 04:38 AM   #1
leaveone
LQ Newbie
 
Registered: Aug 2006
Location: Chesapeake, VA
Distribution: Debian Sarge
Posts: 17

Rep: Reputation: 0
Unhappy Problems with cron running a C++ program


Hello All,
I have written a C++ program that goes to a website (Astronomy Picture of the Day) and downloads an image then sets it as my background using the fbsetbg -f (filename) command on a daily basis. The program is basically a bunch of system commands and it works perfectly if run manually. When cron runs it i get an e-mail with the following contents..


From brandon@localhost.localdomain Wed Aug 02 05:00:02 2006
Envelope-to: brandon@localhost.localdomain
Delivery-date: Wed, 02 Aug 2006 05:00:02 -0400
From: root@localhost.localdomain (Cron Daemon)
To: brandon@localhost.localdomain
Subject: Cron <brandon@wembley> $HOME/code/astro
X-Cron-Env: <SHELL=/bin/sh>
X-Cron-Env: <HOME=/home/brandon>
X-Cron-Env: <PATH=/usr/bin:/bin>
X-Cron-Env: <LOGNAME=brandon>
Date: Wed, 02 Aug 2006 05:00:02 -0400

/usr/bin/fbsetbg: line 169: xmessage: command not found


now the SHELL i use is actually /bin/bash but im not sure if that matters for this. the fbsetbg command IS in my path so im not sure where this command not found message is coming from. furthermore, when i check to see if the image has been downloaded into the designated folder it is there.

also, my crontab -l looks like this..

00 5 * * * $HOME/code/astro

does anyone have a clue as to what im doing or not doing correctly??
 
Old 08-02-2006, 06:25 AM   #2
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600
/usr/bin/fbsetbg: line 169: xmessage: command not found
It's xmessage that gets complained about: check if adding a PATH to your crontab works.
 
Old 08-02-2006, 06:53 AM   #3
marozsas
Senior Member
 
Registered: Dec 2005
Location: Campinas/SP - Brazil
Distribution: SuSE, RHEL, Fedora, Ubuntu
Posts: 1,499
Blog Entries: 2

Rep: Reputation: 68
The /usr/bin/fbsetbg is a program that works only in a graphical environment. It not runs in console mode.

A cron job not inherits your graphical environment, so this why is not works.

The best solution is not to run it by cron. Instead run it by the ways your window system provides to run programs at startup time. In that way, the program inherits your graphical environment.

Another approach is rewrite the program in two separated tasks: one for download images only, and the other set your background from images the first one downloaded early. The first can be put in cron. The other runs at graphical login time.

You can even use standard features from your Window manager to change the background from a set of images. KDE has that feature. In gnome you can use a program name wallpapertray.
 
Old 08-02-2006, 07:15 AM   #4
leaveone
LQ Newbie
 
Registered: Aug 2006
Location: Chesapeake, VA
Distribution: Debian Sarge
Posts: 17

Original Poster
Rep: Reputation: 0
ok so im not too sure how to add the path to xmessage into my crontab.. the xmessage module is in /usr/X11R6/bin/ so if i add that to path then it should work just fine.. i think. any ideas on how to add that to path? when i do an echo $PATH at commandline it shows up as being in the path but apparently crontab uses its own.. i tried editing the system-wide file (/etc/crontab) but that didnt fix the problem either.. any guesses??
 
Old 08-02-2006, 08:01 AM   #5
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600
A cron job not inherits your graphical environment, so this why is not works.
If you're the only one running X(org) this could be remedied by exporting the right DISPLAY variable (and if the job would be run by another user you probably also need to merge Xauth auth).


im not too sure how to add the path to xmessage into my crontab
AFAIK your crontab should look like this:
Code:
PATH=/usr/bin:/bin:/usr/X11R6/bin
00 5 * * * $HOME/code/astro
If it doesn't accept path modification that way you could probably also
Code:
00 5 * * * env PATH=/usr/bin:/bin:/usr/X11R6/bin $HOME/code/astro
 
Old 08-02-2006, 08:40 AM   #6
leaveone
LQ Newbie
 
Registered: Aug 2006
Location: Chesapeake, VA
Distribution: Debian Sarge
Posts: 17

Original Poster
Rep: Reputation: 0
i will try that idea when i get home.. just out of curiousity.. how would i export the correct display? i know that there is an export command but im not familiar with the syntax or what variables i would need to actually export.. thanks for your help!!
 
Old 08-02-2006, 09:41 AM   #7
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600
The "env" bit isn't necessary anyway, so:
Code:
00 5 * * * DISPLAY=":0.0" PATH=/usr/bin:/bin:/usr/X11R6/bin $HOME/code/astro
* Fbsetbg is "just" a wrapper so you could use your favourite background loading app directly instead. Those commandline tools probably won't pop up a graphical dialog to display error messages.
 
Old 08-02-2006, 01:05 PM   #8
leaveone
LQ Newbie
 
Registered: Aug 2006
Location: Chesapeake, VA
Distribution: Debian Sarge
Posts: 17

Original Poster
Rep: Reputation: 0
yep that worked! thanks unSpawn! i always know i can count on this forum to help me out. oh by the way, i used to have another login name for these forums but i guess they made it inactive or something? does anybody know what happened?
 
Old 08-02-2006, 02:38 PM   #9
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600
yep that worked!
Cool.


i used to have another login name for these forums but i guess they made it inactive or something?
AFAIK accounts are not deactivated unless the user requests it or if LQ deems it necessary due to LQ Rule violations (but then you definately would know it). For restoration, deactivation or general account enquiries you best ask Jeremy.
 
  


Reply



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
Verifying a program is running by cron job, if not starting it. AsstInterests Linux - General 8 04-25-2006 02:48 PM
Python program not running from cron spiri Linux - Software 7 03-09-2006 02:02 AM
running java program through cron manu82 Linux - Software 2 02-28-2006 10:35 PM
system("top") in a C program giving problems when the C prg is run by cron rags2k Programming 1 09-02-2004 03:25 PM
Problems Running a perl program SNike3 Linux - Software 2 07-10-2004 07:47 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Debian

All times are GMT -5. The time now is 01:58 PM.

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
Open Source Consulting | Domain Registration