Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
[Solved] Cant grab screenshots via crontab - scrot or import
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Other Things Gentoo
View previous topic :: View next topic  
Author Message
quag7
Apprentice
Apprentice


Joined: 12 Aug 2002
Posts: 288
Location: Marana, Arizona - USA

PostPosted: Wed Jan 14, 2009 11:14 pm    Post subject: [Solved] Cant grab screenshots via crontab - scrot or import Reply with quote

OK, this is frustrating me.

I have /etc/crontab set up to capture a screenshot once per minute:

Code:

* *     * * *   quag7 /scripts/screenshot/screenshot.sh


Various threads here and elsewhere indicate that I have to specify the display to capture (Is there any way to verify the display # - a command line app that will tell me that, for example? I assume it is :0 or :0.0 as it is the only one running on here.)

Here is screenshot.sh - the two lines are in there just because I've tried both, and both fail, though they work if I run the script manually from the command line. Which leads me to believe this is a problem each is having running as a cronjob, talking to the X display. I'm not sure how to get some good error messages to be sure. Of the two, I'd rather use scrot, as it is more efficient/quicker.

Note that I have also tried DISPLAY=:0.0 with the same result. In theory this should not even be necessary on the first line since it has a command line parameter specifying the display.

Code:

#!/bin/sh

DISPLAY=:0 import -quality 100 -window root -display :0.0 /mnt/global/rawscreenshot-import.jpg
DISPLAY=:0 scrot -q 100 /mnt/global/rawscreenshot-scrot.jpg


I have also tried just putting those lines directly (not running it as a script) into /etc/crontab with the same result.

Does anyone have any ideas or see something obviously wrong? I've googled repeatedly and found a few threads here on the Gentoo forums but nothing will work.

Alternatively, any kind of workaround, other software, or other method, would be acceptable, if anyone is doing something similar using different stuff.

Thanks.

Solution:

The command:

Code:
xhost +local:username
will fix permissions issues preventing screencap software from capturing via a cronjob / crontab. I put this command in a script which I then put a symlink to in ~/.kde/Autostart so the command would be run each time X started (If you don't run KDE, put it in the startup/autostart of whatever WM you use).

Code:

#!/bin/sh
xhost +local:quag7

_________________
http://www.dataswamp.net


Last edited by quag7 on Thu Jan 15, 2009 4:56 am; edited 2 times in total
Back to top
View user's profile Send private message
Sadako
Advocate
Advocate


Joined: 05 Aug 2004
Posts: 3792
Location: sleeping in the bathtub

PostPosted: Thu Jan 15, 2009 12:10 am    Post subject: Reply with quote

Could be a permissions problem too, ie even if it's trying to access the correct display, access may be denied.

Is this running in the crontab of the user who started or is logged in to X?

If so, try adding "XAUTHORITY=~/.Xauthority" to the command, in the same way you added DISPLAY.

To actually get some error output, append " > foo.log 2>&1" to the end of the command, which will redirect both stdout and stderr to "foo.log", and hopefully will tell you what's actually going wrong.
_________________
"You have to invite me in"
Back to top
View user's profile Send private message
quag7
Apprentice
Apprentice


Joined: 12 Aug 2002
Posts: 288
Location: Marana, Arizona - USA

PostPosted: Thu Jan 15, 2009 12:33 am    Post subject: Reply with quote

Hopeless wrote:
Could be a permissions problem too, ie even if it's trying to access the correct display, access may be denied.

Is this running in the crontab of the user who started or is logged in to X?


Yes. The system is basically one user - me. I log in as me (quag7) and run startx under that account. The crontab then runs the script (or commands) also as quag7.

Hopeless wrote:

If so, try adding "XAUTHORITY=~/.Xauthority" to the command, in the same way you added DISPLAY.


Did that. No change, unfortunately.

Hopeless wrote:

To actually get some error output, append " > foo.log 2>&1" to the end of the command, which will redirect both stdout and stderr to "foo.log", and hopefully will tell you what's actually going wrong.


OK, this is what I have:

Code:

* *     * * *   quag7 XAUTHORITY=~/.Xauthority DISPLAY=:0 /scripts/screenshot/screenshot.sh > /tmp/screenshot.log 2>&1
* *     * * *   quag7 XAUTHORITY=~/.Xauthority DISPLAY=:0 /usr/bin/scrot '/tmp/directcmd-scrot.jpg' -q 100 > /tmp/screenshot.log 2>&1
* *     * * *   quag7 XAUTHORITY=~/.Xauthority DISPLAY=:0 /usr/bin/import -window root -display :0 /tmp/directcmd-import.jpg > /tmp/screenshot.log 2>&1


screenshot.log is never created.

No difference in results.

I am going to try this on my lesser Debian machine to see if the behavior is the same.

EDIT #2:

All commands are dumping the same basic error now. The question is how to fix it and indeed it is a permissions error. But this perplexes me since both X and the cronjob are running as the same user....hmmm

Code:

Xlib: connection to ":0.0" refused by server
Xlib: No protocol specified

giblib error: Can't open X display. It *is* running, yeah?

_________________
http://www.dataswamp.net
Back to top
View user's profile Send private message
Sadako
Advocate
Advocate


Joined: 05 Aug 2004
Posts: 3792
Location: sleeping in the bathtub

PostPosted: Thu Jan 15, 2009 12:46 am    Post subject: Reply with quote

quag7 wrote:
Something is dumping an error into screenshot.log now - need to change the > to >> to get a better idea of what.

Code:

Xlib: connection to ":0.0" refused by server
Xlib: No protocol specified

giblib error: Can't open X display. It *is* running, yeah?
Yes, sorry, as you're using it on more than one command, you'll need either '>>' or a different log file per command as it'll be get overwritten by the subsequent commands otherwise...

Anyways, "Xlib: connection to ":0.0" refused by server", so it is a permissions issue...

Just run `xhost + local:` in an xterm and that should allow it to work, but isn't the safest method, although for a single user system it shouldn't make much difference.
_________________
"You have to invite me in"
Back to top
View user's profile Send private message
quag7
Apprentice
Apprentice


Joined: 12 Aug 2002
Posts: 288
Location: Marana, Arizona - USA

PostPosted: Thu Jan 15, 2009 12:48 am    Post subject: Reply with quote

Hopeless wrote:
Yes, sorry, as you're using it on more than one command, you'll need either '>>' or a different log file per command as it'll be get overwritten by the subsequent commands otherwise...

Anyways, "Xlib: connection to ":0.0" refused by server", so it is a permissions issue...

Just run `xhost + local:` in an xterm and that should allow it to work, but isn't the safest method, although for a single user system it shouldn't make much difference.


Indeed, thank you for your help. I did that and it seems to work alright now, but I'm not sure why this is necessary, given that quag7 should have access to this already - anyway, that does work.

Thanks again.
_________________
http://www.dataswamp.net
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Other Things Gentoo All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum