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
  • 82,867
  • 54
  • 239
  • 271
Thomas Shields
  • 151
  • 1
  • 5
  • you want to switch to another user, but still be able to take screen shots of your previous user's session, right ? – Sergiy Kolodyazhnyy Jun 03 '15 at 05:48
  • No, I want to switch to another user and have the screenshot cron job from the previous user take screenshots of what's ACTUALLY on the screen, rather than the previous user's session – Thomas Shields Jun 03 '15 at 06:19
  • I'd suggest you make a shell script with while loop that will take screenshot and then sleep x minutes you want ; store it in `/usr/bin` to be accessible to all users, and then make a .desktop file in `/etc/xdg/autostart` folder to make it available for each user. As for storing screenshots . . . .if you use `gnome-screenshot` it stores screenshots in current users directory. You might wanna add another variable that will be incremented and use -f flag in the gnome-screenshot to store screnshot with that variable as name. Or use $(date). – Sergiy Kolodyazhnyy Jun 03 '15 at 06:33
  • @Serg I was considering going down that route. I'll give it a shot asap and report back – Thomas Shields Jun 03 '15 at 06:41

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
  • 31,627
  • 16
  • 118
  • 187
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.

Trey Gordon
  • 212
  • 1
  • 15
  • Also, you had better have a good reason to be viewing these screenshots from other users. This is probably a security risk, seeing as how the files can be read from the hard drive in the event of unauthorized access. – Trey Gordon Jun 03 '15 at 06:07
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
  • 82,867
  • 54
  • 239
  • 271