gpt4 book ai didi

Linux: journalctl

转载 作者:太空宇宙 更新时间:2023-11-04 10:30:36 25 4
gpt4 key购买 nike

我只想查看指定时间范围 (08:00 - 11:00) 内所有日期创建的日志消息。

如果我使用:

journalctl --since 08:00 --until 11:00

它只显示当天的日志。

有什么想法吗?

最佳答案

首先 - 您的 journalctl 日志文件在哪里?默认journalctl收集自系统启动以来的日志。

默认情况下,日志文件位于/var/log/journal。如果此目录不存在,请在 /etc/systemd/journald.conf 中设置 Storage=persistent 并运行 systemctl restart systemd-journald

当 journalctl 保存所有日期的所有消息/事件时,或者当系统从保存设置日的几天收集日志时,您可以通过这种方式从 journalctl 中提取一些有趣的信息:

# Define year
year="2016"

# Defines the month in which you want to search
months=(08 09 10)

for i in "${months[@]}" ; do

# To set a range of days: 14 - 20
for j in `seq 14 20` ; do
journalctl --since "${year}-${i}-${j} 08:00:00" --until "${year}-${i}-${j} 11:00:00" >> /tmp/journal.${year}-${i}-${j}.log
done

done

如果你想检查从 1 到 9 的天数,可能需要添加一个机制来添加 0 (01, 02, 03, ..., 09)。

这是一个示例,您必须根据自己的需要进行调整。

关于Linux: journalctl,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40152339/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com