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?

4
  • you want to switch to another user, but still be able to take screen shots of your previous user's session, right ? Jun 3, 2015 at 5: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 Jun 3, 2015 at 6: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). Jun 3, 2015 at 6:33
  • @Serg I was considering going down that route. I'll give it a shot asap and report back Jun 3, 2015 at 6:41

3 Answers 3

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!

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.

1
  • 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. Jun 3, 2015 at 6: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.

5
  • But the cron job is still running. If I have root access, I don't see why I can't grab the logged in user's screen rather than my own. Jun 3, 2015 at 6:20
  • Every user has his own cron which works for his own session.
    – Maythux
    Jun 3, 2015 at 6:21
  • and as i said above the session will be just locked at the login window when you switch user.
    – Maythux
    Jun 3, 2015 at 6:22
  • Right, I get that. But it's not like the cron job for my user stops running. Jun 3, 2015 at 6:22
  • It will not stop running since your session is still active, you have to logout or you can create a new cron to kill the first when locking your screen
    – Maythux
    Jun 3, 2015 at 6:23

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .