2

(Forgive me if my terminology is not quite accurate here)

I have a cron job set up that uses scrot to take screenshots of my desktop at various intervals.

However, when I switch user to another account (without logging off) the screenshots that come back are just shots of the lock screen.

Is there anyway for me to get a screenshot of the current user's session? I.e, what is actually on the screen?

Maythux
  • 87,123

3 Answers3

3

As far as X11 is concerned, when you switch to another user, that user is on a completely different display.

In you session, if you execute:

echo $DISPLAY

you will have :0, the first virtual display. In the second user, the same will give you :1, the second display.

You can see the screens in use with the command w:

[romano:~] % w  
 11:32:03 up  1:05,  8 users,  load average: 0,10, 0,24, 0,30
USER     TTY      FROM             LOGIN@   IDLE   JCPU   PCPU WHAT
romano   :0       :0               10:27   ?xdm?   6:25   0.13s gdm-session-wor
romano   pts/1    :0               11:03   26:49   0.10s  0.10s zsh
romano   pts/3    :0               11:21    0.00s  0.12s  0.01s w
default  :1       :1               11:24   ?xdm?   6:25   0.07s gdm-session-wor
default  pts/15   :1               11:24    1:56   0.05s  0.05s bash

To be able to do a screenshot from one screen of the other, or from another user, the user to be "shotted" must issue the command

xhost + 

to enable access (not even root will be able to do the snapshot otherwise). After that, you can do a

DISPLAY=:1 scrot 

from a script or another user. Notice that if you shot a screen which is not active (displayed) you will have a black screen or strange things --- who knows what's in the video buffer memory...

Now it's up to you to write a script exploring all this... you should in principle detect which user is active (not easy --- or simply shot all of the screen and discard the black ones after) and do the screenshot.

Good luck!

Rmano
  • 32,167
0

You need to store the screenshots in publicly viewable areas, and also the xserver locks the screen on user switching (not a demonstrated fact, but a reasonable assumption). You probably need to set up an xserver to display this to a file in the home directory, so that when the cron job is called, you fire up the xserver to render the screen to file, rather than for the display.

0

When you switch to other user then you are opening a new session for the new user, and the old session for first user is just on the login. This is a normal attitude of cron, cron is associated to first user so it will just work with his session only.

I hope you understand what I mean. I'm not that good in English anyway, to make it works for the other user, you have to create the same cron for the second user, so that you can take the shots for every user.

Maythux
  • 87,123