Latest LQ Deal: Linux Power User Bundle
Go Back > Forums > Linux Forums > Linux - Desktop
User Name
Linux - Desktop This forum is for the discussion of all Linux Software used in a desktop context.


  Search this Thread
Old 02-15-2007, 06:38 PM   #1
LQ Newbie
Registered: Feb 2007
Posts: 3

Rep: Reputation: 0
running kde apps as cron tasks

I have the following script--

cat /root/tmp/

/bin/echo ! >> /root/tmp/test
/usr/bin/import -window root /root/tmp/test.jpg
/bin/echo !! >> /root/tmp/test

(import being the screen dump utility that comes with ImageMagick.)

I have it configured to run as a cron task--

crontab -l:

*/2 * * * * /root/tmp/

the first and second echos execute; the file /root/tmp/test is modified as expected. But the command in between does not leave the screen dump. When I run the script from a prompt, it does, so this problem must be in connection with the way cron is running it. Does cron have a problem executing X apps? What am I missing about my understanding of cron? e.g., I would expect that if I put in the following task in my crontab,

*/2 * * * * /usr/bin/firefox

the browser will be regularly loading. This doesn't happen. If I do this with

*/2 * * * * /bin/ls >> some_capture

it does, so it isn't my cron setup. Any clarification would be appreciated, Thanks!
Old 02-16-2007, 02:23 PM   #2
Registered: Feb 2004
Location: Olympia, WA
Distribution: SolydK
Posts: 442
Blog Entries: 3

Rep: Reputation: 60
Cron jobs are not associated with a particular user session. They execute in a separate environment. If you try to run Firefox from cron, you have to tell it what X session to start in. If you want to take a screenshot from a cron session you have to tell it what session to use as well. You may need to define a DISPLAY environment variable for cron to use, such as DISPLAY=:0.0 for the first X session.
Old 02-16-2007, 02:47 PM   #3
Registered: Mar 2003
Location: Cambridge, MA, USA
Distribution: Ubuntu (Dapper and Heron)
Posts: 377

Rep: Reputation: 31
(I know it's a frequent answer--) What are you trying to achieve? Please explain why you are doing this!

What if someone else is logged in on the first display at the scheduled time? Your script should fail, because you don't have access to their X server, right?

What if no one is logged in?

BTW, you should have gotten a diagnosic like import: unable to open X server `'.. (Try this: unset DISPLAY then run your script.) If there is any output (including to stderr), cron will mail it to you. Check your mailbox on the machine where your cron job runs. If this is inconvenient, add (replace with your real e-mail).
Old 02-17-2007, 10:39 AM   #4
LQ Newbie
Registered: Feb 2007
Posts: 3

Original Poster
Rep: Reputation: 0
Quigi, the reason I was doing this was just because I used to take random screenshots manually and I get a kick now out of looking at what was on my screen say in the mid 90s. I wanted to automate this as a kind of screenshot archiving using cron. And hopefully I won't have midget bestiality porn up at the scheduled time.

But seriously, to answer your other question, I was testing teh DISPLAY variable, so import wouldn't run if no one was logged in to X.

penguinator, thanks for the tip, it works now. I guess I basically didn't understand "where" cron was running a scheduled task, and so I had to set DISPLAY myself (and also make sure permissions between my X session and cron task agreed, which I realized next). So e.g. a script with "export DISPLAY=:0; /usr/bin/firefox" works as expected when scheduled. Thanks for the advice!


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
Cron - doesn't seem to run scheduled tasks robintw Linux - General 11 11-25-2005 01:53 AM
All cron tasks fail Ateo Linux - Software 2 06-11-2005 01:34 PM
running kde apps in fluxbox bingbang Linux - Newbie 2 05-01-2004 10:10 AM
cron tasks MaverickApollo Linux - Software 1 02-02-2004 01:06 PM
Running Gnome apps in KDE PDR60 Slackware 1 11-24-2003 09:18 AM > Forums > Linux Forums > Linux - Desktop

All times are GMT -5. The time now is 02:23 PM.

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