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

Here is another solution using "dbus-monitor". A little bash script logging screen activity.

exit_report(){
echo "$(date) Monitoring Terminated."
}
trap "exit_report; exit;" 0

lockmon() {
adddate() {
    while IFS= read -r line; do
      echo "$(date) $line" | grep "boolean" | sed 's/   boolean true/Screen Locked/' | sed 's/   boolean false/Screen Unlocked/'
    done
}
echo "$(date) Monitoring Started."
dbus-monitor --session "type='signal',interface='org.gnome.ScreenSaver'" | adddate

}

lockmon >> lock_screen.log

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


Yes it doesn't seem to be logged anywhere for you. @tutuDajuju has a good solution so I thought I'd port it to bash (and remove the dependence on using gnome, this should work regardless of desktop environment) for those that are interested.
If you have this running in the background and pipe it to a log file you will have your log.

#!/bin/bash

#prints out, among other things;
#      string "org.kde.screensaver"
#transform it to 'org.kde.screensaver'
service=$(\
    dbus-send \
        --session \
        --dest=org.freedesktop.DBus \
        --type=method_call \
        --print-reply \
        /org/freedesktop/DBus org.freedesktop.DBus.ListNames \
    | grep -o '[^"]*.screensaver'
)

#prints out, among other things;
#method bool org.freedesktop.ScreenSaver.SetActive(bool e)
#transform it to 'org.freedesktop.ScreenSaver'
interface=$(
    qdbus \
        $service /ScreenSaver \
    | grep -oP '[^ ]*(?=.SetActive)'
)

path='/ScreenSaver'

#monitor it with a while loop
dbus-monitor "type='signal',interface='$interface',member='ActiveChanged',path='$path'" \
| while read -r line; do
    #ignore the metadata and pull the 'boolean <true/false>' line
    read line

    #check if it is set to true
    if echo $line | grep -q 'true'; then
        echo "Locked at $(date)"
    else
        echo "Unlocked at $(date)"
    fi
done

This ran fine on my Fedora with KDE, but I guess it should work on other things like Debian with gnome et cetera.
You may have issues if your grep doesn't support -P (in which case you can just use sed).