How can I know when my screen was locked last time?

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.


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:

  • Logging lock-screen events
  • Run script on screen lock/unlock

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