Unixhelp
Unixhelp

Reputation: 7

One line command for getting data from logs

I have apache logs which are updated every minute something like this

Apache.log

00:00:01 up 137
00:01:01 up 132
00:02:01 up 137
00:03:01 up 134
00:04:01 up 150

I want one line command or a small Unix script that will echo a message whenever the last column value is more than 140 as in the last line and the script still continue to run.

So in short I want a script/command to monitor this log every minute and echo a message if last column value exceeds 140.

Upvotes: 0

Views: 60

Answers (3)

Zahid Sumon
Zahid Sumon

Reputation: 426

if you want to monitor it on regular interval you might use watch command in terminal or add one process in conky application for showing on desktop

Upvotes: 0

masudak
masudak

Reputation: 171

You can also use perl like this.

$ tailf Apache.log | perl -anle 'if($F[2] > 140){print}'
00:04:01 up 150

OR you can also use elasticsearch and process the input data as you like.

Upvotes: 0

Jonathan Leffler
Jonathan Leffler

Reputation: 754700

tail -f log.file | awk '$NF > 140 { print }'

Continually monitor the file; when a line has more than 140 in the last column, print it.

That will work for some simpler uses, at any rate. There are issues that could make it more problematic. If you send the output of awk to file (or anything other than a terminal), you may not get the output written timely.

Upvotes: 3

Related Questions