21

Exist a log where I can look for that information? I want to know last days when my PC automatically locked the screen because was idle.

Radu Rădeanu
  • 174,089
  • 51
  • 332
  • 407

3 Answers3

13

You can find the unlock screen events using the following command:

grep screen /var/log/auth.log*

But there is not so simple to find the lock screen events because by default doesn't exist any log for these events (as far as I know).

Anyway, you can run the following command for logging the lock screen events:

dbus-monitor --session "type='signal',interface='org.gnome.ScreenSaver'" | ( while true; do read X; if echo "$X" | grep "boolean true" &> /dev/null; then  echo "Screen locked on $(date)" > $HOME/lock_screen.log; fi; done )

in ~/lock_screen.log file.

If you like the above command, then use it in a script and make the script to run automatically at startup.

References:

Radu Rădeanu
  • 174,089
  • 51
  • 332
  • 407
2

FWIW: what works for me on Ubuntu 16.04.4 LTS with Unity, is monitoring DBUS with the following command:

dbus-monitor --session "type='signal',interface='com.canonical.Unity.Session'"

...and then monitoring for "Locked" and "Unlocked" events. Example output:

signal time=1525269138.855107 sender=:1.51 -> destination=(null destination) serial=86735 path=/com/canonical/Unity/Session; interface=com.canonical.Unity.Session; member=LockRequested

signal time=1525269139.409261 sender=:1.51 -> destination=(null destination) serial=86892 path=/com/canonical/Unity/Session; interface=com.canonical.Unity.Session; member=Locked

signal time=1525269151.238899 sender=:1.51 -> destination=(null destination) serial=86937 path=/com/canonical/Unity/Session; interface=com.canonical.Unity.Session; member=UnlockRequested

signal time=1525269151.791874 sender=:1.51 -> destination=(null destination) serial=86938 path=/com/canonical/Unity/Session; interface=com.canonical.Unity.Session; member=Unlocked

0

This is what I use in Ubuntu 16.04. It logs to the system syslog.

Add to your home folder, mark as executable, and then use gnome-session-properties to configure it to run on session startup.

#!/bin/bash

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

lockmon() {
adddate() {
    while IFS= read -r line; do
      echo $line | grep string | grep '"start"' -q
      if [ $? -eq 0 ] ; then
        logger "$(date) Screen locked"
      fi
      echo $line | grep string | grep '"stop"' -q
      if [ $? -eq 0 ] ; then
        logger "$(date) Screen unlocked"
      fi
    done
}
logger "$(date) Lockscreen Monitoring Started."
dbus-monitor --session "type='signal',interface='com.ubuntu.Upstart0_6.Instance'" | adddate
}

lockmon

Based on a similar answer for Fedora systems.

jjmontes
  • 363