Answers:
在中/var/log/pm-suspend.log
,查找最后一行,如下所示:
Sun Dec 16 09:30:31 CET 2012: Awake.
那是您最后一次唤醒时间。从那以后,您就可以计算出您的正常运行时间了,保罗提出了建议。
您的logrotate
遗嘱会定期“旋转”日志以防止它们变得太大,因此您可能会发现一个空pm-suspend.log
文件。在这种情况下,只需查找pm-suspend.log.1
文件(您可能还会找到其他名为like等的日志文件pm-suspend.log.2.gz
;您可以使用zcat
或检查它们zless
)。
pm-suspend.log
是空的怎么办?:(
cat /var/log/pm-suspend.log /var/log/pm-suspend.log.1 | grep -B1 Awake; echo "--"; zcat /var/log/pm-suspend.log.*.gz | grep -B1 Awake
对于运行systemd的台式机/服务器,虽然没有直接命令可以直接告诉信息(据我所知),但所有数据都记录在日志中。
您可以grep日记,例如:
echo ">> [SUSPEND] Times during current boot"
journalctl -b 0 |grep "]: Suspending system..."
echo ">> [WAKE] Times during current boot"
journalctl -b 0 |grep "PM: Finishing wakeup"
或者,为获得出色的输出效果,我编写了一个python3脚本(在Fedora 23上运行良好)示例输出:
Initial Boot Timestamp: 2016-01-15 09:31:32
Wake Timestamp | Suspend Timestamp | Awake Time |
-------------------- | -------------------- | -------------------- |
2016-01-15 09:31:32 | 2016-01-15 09:36:03 | 0h 4m |
2016-01-15 09:36:22 | 2016-01-15 19:15:04 | 9h 38m |
2016-01-15 19:22:21 | 2016-01-15 20:00:05 | 0h 37m |
...
------------------- | -------------------- | -------------------- |
Summary: Days Since Boot [8.23] | Days Awake [4.14] | Suspend/Wake Cycles: [28]
该脚本在github中。链接到github repo
journalctl -b 0 -o short-iso MESSAGE="PM: Finishing wakeup." | tail -1 | cut -d" " -f1
最后一个唤醒的只是时间
pm-suspend程序不是如何挂起计算机的唯一选择。我的程序日志现在为空,但是我发现了更可靠的命令:
cat /var/log/syslog | grep 'systemd-sleep' | grep "Suspending\|resumed"
输出为:
Oct 2 09:11:48 dmatej-lenovo systemd-sleep[931]: Suspending system...
Oct 2 09:53:10 dmatej-lenovo systemd-sleep[931]: System resumed.
Oct 2 15:02:48 dmatej-lenovo systemd-sleep[27516]: Suspending system...
Oct 2 16:07:19 dmatej-lenovo systemd-sleep[27516]: System resumed.
Oct 2 16:32:48 dmatej-lenovo systemd-sleep[29622]: Suspending system...
Oct 2 17:16:41 dmatej-lenovo systemd-sleep[29622]: System resumed.
Oct 3 00:24:58 dmatej-lenovo systemd-sleep[21316]: Suspending system...
Oct 3 08:17:22 dmatej-lenovo systemd-sleep[21316]: System resumed.
Oct 3 09:09:25 dmatej-lenovo systemd-sleep[24739]: Suspending system...
Oct 3 09:50:47 dmatej-lenovo systemd-sleep[24739]: System resumed.
修改更好的步骤验证
grep ': Awake' /var/log/pm-suspend.log
编辑哈哈感谢您的评论:D
cat
积分!
这些答案都不适合我。但我有用地发现sleep.target
了正是出于以下原因:
$ journalctl -n4 -u sleep.target
nov. 17 17:16:37 kaa systemd[1]: Reached target Sleep.
nov. 17 18:46:22 kaa systemd[1]: Stopped target Sleep.
nov. 17 19:27:31 kaa systemd[1]: Reached target Sleep.
nov. 17 19:45:21 kaa systemd[1]: Stopped target Sleep.