我怎么知道我的屏幕上次锁定的时间?

存在我可以查找该信息的日志? 我想知道我的电脑因为空闲而自动锁定屏幕的最后几天。

您可以使用以下命令找到解锁屏幕事件:

grep screen /var/log/auth.log* 

但是找到锁屏事件并不是那么简单,因为默认情况下不存在这些事件的任何日志(据我所知)。

无论如何,您可以运行以下命令来记录锁定屏幕事件:

 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 ) 

~/lock_screen.log文件中。

如果您喜欢上面的命令,那么在脚本中使用它并使脚本在启动时自动运行。

参考文献:

  • 记录锁定屏幕事件
  • 在屏幕锁定/解锁时运行脚本

FWIW:在Ubuntu 16.04.4上使用Unity的LTS对我有用,用以下命令监视DBUS:

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

…然后监视“已锁定”和“未锁定”事件。 输出示例:

signal time = 1525269138.855107 sender =:1.51 – > destination =(null destination)serial = 86735 path = / com / canonical / Unity / Session; 接口= com.canonical.Unity.Session; 构件= LockRequested

signal time = 1525269139.409261 sender =:1.51 – > destination =(null destination)serial = 86892 path = / com / canonical / Unity / Session; 接口= com.canonical.Unity.Session; 构件=锁定

signal time = 1525269151.238899 sender =:1.51 – > destination =(null destination)serial = 86937 path = / com / canonical / Unity / Session; 接口= com.canonical.Unity.Session; 构件= UnlockRequested

signal time = 1525269151.791874 sender =:1.51 – > destination =(null destination)serial = 86938 path = / com / canonical / Unity / Session; 接口= com.canonical.Unity.Session; 构件=解锁

这是我在Ubuntu 16.04中使用的。 它会记录到系统syslog。

添加到您的主文件夹,标记为可执行文件,然后使用gnome-session-properties将其配置为在会话启动时运行。

 #!/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 

基于Fedora系统的类似答案 。