1

I need to read the contents of a file mycustomfile.log every 30 minutes in linux

I tried egrep "06:00| 06:30"

But am not getting the results I want.

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

the above results highlighted with ** are in amongst correct entries. I need to exclude them, and I need to see the results in 30 minutes interval.

What am I missing?

UPDATE Below is my input file :

[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
4
  • Can you please provide sample of the input file, and a sample of expected result? Commented Mar 30, 2017 at 7:44
  • yes, i have provided the output its generated . i need to avoid the 07:06:30 entry and 07:07 entry . it has to be in the interval of 30 minutes, but here it sometimes show as 1 minute interval. Commented Mar 30, 2017 at 7:45
  • the command you entered cannot possibly have produced that output from that input file. Please could you show us exactly what you want to see? Commented Mar 30, 2017 at 8:07
  • In a recent system you can use journalctl. journalctll -u mpmstats --since 06:00 --until 06:30 Commented Mar 30, 2017 at 9:09

1 Answer 1

0

The grep pattern you are using can provides minutes:seconds instead of hours:minutes

The following grep will be more accurate:

Note that I added ":" after the minutes, to indicates that there are also seconds afterwards.

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

Or a more general grep:

egrep ":00:|:30:"
1
  • 1
    Thanks Yaron , for your help. egrep ":00:|:30:" is working peRFectly. Commented Mar 30, 2017 at 8:39

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.