每 30 分钟读取一次日志文件内容时出现问题

每 30 分钟读取一次日志文件内容时出现问题

mycustomfile.log我需要在linux中每30分钟读取一个文件的内容

我试过egrep "06:00| 06:30"

但没有得到我想要的结果。

06:00:24  rdy->395  bsy->205  ka->29 
06:30:27  rdy->339  bsy->261  ka->40 
07:00:30  rdy->259  bsy->341  ka->80 
**07:06:30  rdy->282  bsy->318  ka->73** 
**07:07:30  rdy->234  bsy->366  ka->80** 
07:30:32  rdy->455  bsy->445  ka->85

上面突出显示的结果**属于正确条目。我需要排除它们,并且需要每隔 30 分钟查看一次结果。

我缺少什么?

更新以下是我的输入文件:

[Thu Mar 30 00:00:37 2017] [notice] mpmstats: rdy 26 bsy 49 rd 45 wr 1 ka 3 log 0 dns 0 cls 0

[Thu Mar 30 00:10:38 2017] [notice] mpmstats: rdy 46 bsy 54 rd 53 wr 0 ka 1 log 0 dns 0 cls 0

[Thu Mar 30 00:20:39 2017] [notice] mpmstats: rdy 55 bsy 45 rd 45 wr 0 ka 0 log 0 dns 0 cls 0

[Thu Mar 30 00:30:39 2017] [notice] mpmstats: rdy 48 bsy 52 rd 51 wr 0 ka 1 log 0 dns 0 cls 0

[Thu Mar 30 00:40:40 2017] [notice] mpmstats: rdy 74 bsy 26 rd 23 wr 0 ka 1 log 0 dns 0 cls 2

[Thu Mar 30 00:50:41 2017] [notice] mpmstats: rdy 44 bsy 14 rd 12 wr 0 ka 2 log 0 dns 0 cls 0

[Thu Mar 30 01:00:41 2017] [notice] mpmstats: rdy 41 bsy 9 rd 9 wr 0 ka 0 log 0 dns 0 cls 0

[Thu Mar 30 01:10:42 2017] [notice] mpmstats: rdy 39 bsy 11 rd 5 wr 0 ka 6 log 0 dns 0 cls 0
[Thu Mar 30 01:20:42 2017] [notice] mpmstats: rdy 45 bsy 5 rd 5 wr 0 ka 0 log 0 dns 0 cls 0
[Thu Mar 30 01:30:43 2017] [notice] mpmstats: rdy 31 bsy 19 rd 18 wr 0 ka 1 log 0 dns 0 cls 0
[Thu Mar 30 01:40:44 2017] [notice] mpmstats: rdy 59 bsy 16 rd 16 wr 0 ka 0 log 0 dns 0 cls 0
[Thu Mar 30 01:50:44 2017] [notice] mpmstats: rdy 62 bsy 13 rd 13 wr 0 ka 0 log 0 dns 0 cls 0
[Thu Mar 30 02:00:45 2017] [notice] mpmstats: rdy 70 bsy 5 rd 5 wr 0 ka 0 log 0 dns 0 cls 0
[Thu Mar 30 02:10:45 2017] [notice] mpmstats: rdy 69 bsy 6 rd 5 wr 0 ka 1 log 0 dns 0 cls 0
[Thu Mar 30 02:20:46 2017] [notice] mpmstats: rdy 57 bsy 18 rd 18 wr 0 ka 0 log 0 dns 0 cls 0
[Thu Mar 30 02:30:47 2017] [notice] mpmstats: rdy 69 bsy 6 rd 6 wr 0 ka 0 log 0 dns 0 cls 0
[Thu Mar 30 02:40:47 2017] [notice] mpmstats: rdy 69 bsy 6 rd 6 wr 0 ka 0 log 0 dns 0 cls 0
[Thu Mar 30 02:50:48 2017] [notice] mpmstats: rdy 73 bsy 2 rd 2 wr 0 ka 0 log 0 dns 0 cls 0
[Thu Mar 30 03:30:50 2017] [notice] mpmstats: rdy 72 bsy 3 rd 3 wr 0 ka 0 log 0 dns 0 cls 0
[Thu Mar 30 03:40:51 2017] [notice] mpmstats: rdy 72 bsy 3 rd 3 wr 0 ka 0 log 0 dns 0 cls 0
[Thu Mar 30 03:50:52 2017] [notice] mpmstats: rdy 74 bsy 1 rd 1 wr 0 ka 0 log 0 dns 0 cls 0
[Thu Mar 30 04:00:52 2017] [notice] mpmstats: rdy 74 bsy 1 rd 1 wr 0 ka 0 log 0 dns 0 cls 0
[Thu Mar 30 04:10:53 2017] [notice] mpmstats: rdy 73 bsy 2 rd 2 wr 0 ka 0 log 0 dns 0 cls 0
[Thu Mar 30 04:20:54 2017] [notice] mpmstats: rdy 64 bsy 11 rd 11 wr 0 ka 0 log 0 dns 0 cls 0
[Thu Mar 30 04:30:54 2017] [notice] mpmstats: rdy 71 bsy 4 rd 4 wr 0 ka 0 log 0 dns 0 cls 0

答案1

您使用的 grep 模式可以提供分钟:秒而不是小时:分钟

下面的 grep 会更准确:

请注意,我在分钟后添加了“:”,以指示之后还有秒。

egrep "06:00:|06:30:"

或者更通用的 grep:

egrep ":00:|:30:"

相关内容