Ubuntu 中哪个日志服务保存重启日志

Ubuntu 中哪个日志服务保存重启日志

我需要使用 journald 系统服务单元获取主机重启和关机日志,但我只看到获取重启和关机日志的命令。我们是否有任何服务可以使用 systemd 服务单元获取重启日志。 前任journalctl _SYSTEMD_UNIT=systemd-update-utmp.service

我想知道哪个服务保存所有系统重启日志和关机日志。

答案1

我想知道哪个服务保存所有系统重启日志和关机日志。

它不是执行该操作的 systemd.service。systemd 通常依赖于已有的旧命令。

journalctl -b -1 -n

将显示它,但最后一个探测。您还可以使用

last -x shutdown reboot

选项-n{digit} 将限制其为{digit} 个结果并显示关机和重启。


例子

 last -x shutdown reboot
reboot   system boot  5.4.0-42-generic Mon Aug 24 18:25   still running
shutdown system down  5.4.0-42-generic Mon Aug 24 17:55 - 18:25  (00:29)
reboot   system boot  5.4.0-42-generic Mon Aug 24 17:28 - 17:55  (00:27)
shutdown system down  5.4.0-42-generic Mon Aug 24 08:00 - 17:28  (09:27)
reboot   system boot  5.4.0-42-generic Mon Aug 24 07:31 - 08:00  (00:29)
shutdown system down  5.4.0-42-generic Mon Aug 24 06:54 - 07:31  (00:37)
reboot   system boot  5.4.0-42-generic Sun Aug 23 08:43 - 06:54  (22:10)
shutdown system down  5.4.0-42-generic Sun Aug 23 03:25 - 08:43  (05:17)
reboot   system boot  5.4.0-42-generic Sun Aug 23 02:21 - 03:25  (01:04)
shutdown system down  5.4.0-42-generic Sat Aug 22 23:52 - 02:21  (02:29)

- Logs begin at Tue 2020-03-03 17:27:53 CET, end at Mon 2020-08-24 18:57:10 CE>
aug 24 17:55:45 discworld systemd[1]: Stopped Remount Root and Kernel File Syst>
aug 24 17:55:45 discworld systemd[1]: Reached target Shutdown.
aug 24 17:55:45 discworld systemd[1]: Reached target Final Step.
aug 24 17:55:45 discworld systemd[1]: systemd-poweroff.service: Succeeded.
aug 24 17:55:45 discworld systemd[1]: Finished Power-Off.
aug 24 17:55:45 discworld systemd[1]: Reached target Power-Off.
aug 24 17:55:45 discworld systemd[1]: Shutting down.
aug 24 17:55:45 discworld systemd-shutdown[1]: Syncing filesystems and block de>
aug 24 17:55:45 discworld systemd-shutdown[1]: Sending SIGTERM to remaining pro>
aug 24 17:55:45 discworld systemd-journald[399]: Journal stopped

相关内容