Linux - DesktopThis forum is for the discussion of all Linux Software used in a desktop context.
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Introduction to Linux - A Hands on Guide
This guide was created as an overview of the Linux Operating System, geared toward new users as an exploration tour and getting started guide, with exercises at the end of each chapter.
For more advanced trainees it can be a desktop reference, and a collection of the base knowledge needed to proceed with system and network administration. This book contains many real life examples derived from the author's experience as a Linux system and network administrator, trainer and consultant. They hope these examples will help you to get a better understanding of the Linux system and that you feel encouraged to try out things on your own.
Click Here to receive this Complete Guide absolutely free.
(import being the screen dump utility that comes with ImageMagick.)
I have it configured to run as a cron task--
*/2 * * * * /root/tmp/test_script.sh
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!
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.
(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 MAILTOfirstname.lastname@example.org (replace with your real e-mail).
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!