有没有一个日志可以查找这些信息?我想知道最近几天我的电脑因为闲置而自动锁定屏幕的时间。
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
文件中。
如果你喜欢上述命令,那么将其用于脚本,并使脚本在启动时自动运行。
参考资料:
dbus-monitor --session "type='signal',interface='com.ubuntu.Upstart0_6'"
的输出是signal time=1497336035.520628 sender=org.freedesktop.DBus -> destination=:1.140 serial=2 path=/org/freedesktop/DBus; interface=org.freedesktop.DBus; member=NameAcquired string ":1.140" signal time=1497336035.520706 sender=org.freedesktop.DBus -> destination=:1.140 serial=4 path=/org/freedesktop/DBus; interface=org.freedesktop.DBus; member=NameLost string ":1.140"
,然后当我锁定或解锁时没有任何输出。 - maxbellec对我来说,适用于Ubuntu 16.04.4 LTS和Unity的方法是使用以下命令监视DBUS:
dbus-monitor --session "type='signal',interface='com.canonical.Unity.Session'"
信号时间=1525269138.855107 发送者=:1.51 -> 目标=(null destination) 序列号=86735 路径=/com/canonical/Unity/Session; 接口=com.canonical.Unity.Session; 成员=LockRequested
信号时间=1525269139.409261 发送者=:1.51 -> 目标=(null destination) 序列号=86892 路径=/com/canonical/Unity/Session; 接口=com.canonical.Unity.Session; 成员=Locked
信号时间=1525269151.238899 发送者=:1.51 -> 目标=(null destination) 序列号=86937 路径=/com/canonical/Unity/Session; 接口=com.canonical.Unity.Session; 成员=UnlockRequested
信号时间=1525269151.791874 发送者=:1.51 -> 目标=(null destination) 序列号=86938 路径=/com/canonical/Unity/Session; 接口=com.canonical.Unity.Session; 成员=Unlocked
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
cat screen /var/log/auth.log | grep unlock
- 不需要使用sudo。 - Andrew