gpt4 book ai didi

linux - 从日志文件中提取最近 24 小时的数据

转载 作者:行者123 更新时间:2023-12-05 09:01:13 25 4
gpt4 key购买 nike

我想显示最近 24 小时的日志

我试过了,但这不是最好的动态方式。

utmpdump /var/log/wtmp* | awk '/2022-09-22/, /2022-09-23/'

运行脚本时显示的任何其他方式应该持续 24 小时

日志文件

[8] [528314] [    ] [        ] [pts/1       ] [                    ] [0.0.0.0        ] [2022-09-18T18:44:12,422480+00:00]
[8] [476233] [ ] [ ] [pts/0 ] [ ] [0.0.0.0 ] [2022-09-18T19:25:11,585556+00:00]
[7] [544366] [ts/0] [centos ] [pts/0 ] [92.46.127.82 ] [92.46.127.82 ] [2022-09-19T04:59:51,304439+00:00]
[8] [544366] [ ] [ ] [pts/0 ] [ ] [0.0.0.0 ] [2022-09-19T04:59:51,517787+00:00]
[7] [544366] [ts/0] [centos ] [pts/0 ] [92.46.127.82 ] [92.46.127.82 ] [2022-09-19T04:59:54,121598+00:00]
[8] [544366] [ ] [ ] [pts/0 ] [ ] [0.0.0.0 ] [2022-09-19T04:59:54,361475+00:00]
[7] [544366] [ts/0] [centos ] [pts/0 ] [92.46.127.82 ] [92.46.127.82 ] [2022-09-19T04:59:56,613335+00:00]
[8] [544366] [ ] [ ] [pts/0 ] [ ] [0.0.0.0 ] [2022-09-19T04:59:56,810335+00:00]
[7] [544822] [ts/0] [centos ] [pts/0 ] [92.46.127.82 ] [92.46.127.82 ] [2022-09-19T05:01:33,299161+00:00]
[8] [544822] [ ] [ ] [pts/0 ] [ ] [0.0.0.0 ] [2022-09-19T05:01:33,572603+00:00]
[7] [544822] [ts/0] [centos ] [pts/0 ] [92.46.127.82 ] [92.46.127.82 ] [2022-09-19T05:01:33,897001+00:00]
[8] [544822] [ ] [ ] [pts/0 ] [ ] [0.0.0.0 ] [2022-09-19T05:01:34,152397+00:00]
[7] [544822] [ts/0] [centos ] [pts/0 ] [92.46.127.82 ] [92.46.127.82 ] [2022-09-19T05:01:34,438247+00:00]
[8] [544822] [ ] [ ] [pts/0 ] [ ] [0.0.0.0 ] [2022-09-19T05:01:34,696364+00:00]
[7] [544822] [ts/0] [centos ] [pts/0 ] [92.46.127.82 ] [92.46.127.82 ] [2022-09-19T05:01:34,978371+00:00

最佳答案

不一定是 24 小时(但您的问题也只过滤昨天和今天,而不考虑当前时间),但也许您正在寻找 command substitution替换昨天和今天的日期?

utmpdump /var/log/wtmp* | awk "/$(date -I -dyesterday)/,/$(date -I)/"

关于linux - 从日志文件中提取最近 24 小时的数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/73827374/

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