Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Problem

See the exact date & time a user locks and unlocks his work station - running Fedora 18.

Question

Is there any way to log an event of a user entering and exiting "lock-screen" on fedora 18 (or a general linux solution)?

Tried

  1. Tried looking at /var/log/boot - no help. And looking at /var/log/messages I found the message systemd-logind[xxx]: New session 140 of user YYY, but could not find the lock-screen (gnome?) event.
  2. Tried looking at /var/log/audit/audit.log which has a lot of PAM related messages about all sort of users and services, but I'm not really sure what to look for to find the lock-screen activity
share|improve this question
add comment

3 Answers 3

Try to take a look at /var/log/auth.log. You should see some related messages from PAM and/or the screensaver application.

share|improve this answer
    
I have no /var/log/auth.log, I do have /var/log/audit/audit.log which has a lot of PAM related messages about all sort of users and services, but I'm not really sure what to look for to find the lock-screen activity –  tutuDajuju Oct 21 '13 at 8:24
add comment
up vote 1 down vote accepted

Might as well answer this although it's not my answer (my boss provided me with the solution) to help others with the same need (or curious minds).

tl;dr: Use D-Bus to get lockscreen's actived/deactived signals.

It seems D-Bus messaging is widely supported by GNOME apps, and the ScreenSaver app specifically, and it seems that the gnome-screensaver app is the official locking app for Gnome shell.

So, to test it out, I just ran dbus-monitor and get the response:

dbus-monitor --session "type='signal',interface='org.gnome.ScreenSaver'"

I've written a little python script to log this activity into a file:

#!/usr/bin/env python
from datetime import datetime
import os
import pwd
import subprocess
import time

LOG_FILE = os.path.expanduser('~/hours_log.csv')


cmd = subprocess.Popen(["dbus-monitor \"type='signal',interface="
                        "'org.gnome.ScreenSaver'\""], shell=True,
                       stdout=subprocess.PIPE)

running = 0
while 1:
    time.sleep(0.1)
    if running:
        output = cmd.stdout.readline()
        status = 'unlocked' if 'true' in output else 'locked'
        new_line = "{time} {user} {status} the screen\n".format(
            time=datetime.now().ctime(),
            user=pwd.getpwuid(os.getuid())[0],
            status=status
        )
        with open(LOG_FILE, 'a') as f:
            f.write(new_line)

        running = 0
    line = cmd.stdout.readline()
    if "ActiveChange" in line and 'org.gnome.ScreenSaver' in line:
        running = 1
share|improve this answer
add comment

which screensaver you are using ? if it is xscreensaver, turn on the log options and try to monitor the log file.

http://www.jwz.org/xscreensaver/man1.html

share|improve this answer
    
I just wrote in my own answer that the default in gnome shell is gnome-screensaver, which appears to be what I'm using (since fedora installs gnome shell by default)... –  tutuDajuju Nov 2 '13 at 15:52
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.