我想显示最近 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)/"
https://stackoverflow.com/questions/73827374/
相关文章:
c++ - 如何在始终选择第一个元素并过滤其余元素的范围内创建 View ?
performance - 我可以使此 Clojure 代码(计算图形二分法)更高效吗?
c++ - 我可以继承 std::array 并重载 operator [] 吗?
regex - 包含至少两个数字/字母的序列的 Python 正则表达式
typescript - 为什么 `type T1 = undefined & {}` 从不出现在
python - 在代表 python 中大文件的大字符串上加速 re.sub()?