Linux - DesktopThis forum is for the discussion of all Linux Software used in a desktop context.
Notices
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.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
(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/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 MAILTO=jason.farnon@domain.com (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!
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.