[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

how to highlight certain words while tailing log on unix/linux

Posted on 2012-03-25
10
Medium Priority
?
817 Views
Last Modified: 2012-07-12
Hi,

Is there a way to highlight few words while tailing (tail -f logfile.log) log files on unix or linux.

Bascially, would like to highlight (ONLY the word or the word background color) for certain keywords ex "ERROR" or "FAILED" ...so while tailing (scrolls up) it can be easily noticed.

Right now, I have a script which scans the log file and write only the lines which I'm interested in to a different file...then I open the newly created file and so on.

thanks in advance
0
Comment
Question by:enthuguy
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
10 Comments
 
LVL 84

Accepted Solution

by:
ozo earned 900 total points
ID: 37763873
require Term::Cap;
my $term = Tgetent Term::Cap { TERM => undef, OSPEED => $ospeed };
my $so = $term->Tputs('so');
my $se = $term->Tputs('se');
open T,'tail -f logfile.log|' or die $!;
$|=1;
while( <T> ){
    s/(ERROR|FAILED)/$so$1$se/g;
    print;
}
0
 
LVL 35

Expert Comment

by:Duncan Roe
ID: 37765093
The less command can do what you want (did you know it can act like tail -f?)
less your log file (that is being written to). After a screen of output, you get a prompt.
Enter your search criteria, e.g. /ERROR|FAILED (less search strings are regular expressions).
Eventually you get another prompt (after ERROR or FAILED is displayed, highlighted, on line 1).
At this prompt, enter F (just a capital F). less will tail the file, and you will see highlighted matches as they occur. You can enter Control-C at any time to stop tailing; at which point you can use N (capital N) to visit previous matches.
If you want the match to show some way down the page so you can see preceding context, enter -jnumber at any prompt to set the line number where the matches are displayed.
0
 
LVL 35

Expert Comment

by:Duncan Roe
ID: 37765121
grep --line-buffered can also be you friend. E.g. tail -f logfile.log | grep --line-buffered -E -v stuff you don't want to see | less
Drive less as per previous post
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

Author Comment

by:enthuguy
ID: 37765488
thanks all

Getting exicted now...will try this tomorrow and let you know :)

thanks again
0
 

Author Comment

by:enthuguy
ID: 37765497
Hi ozo, do I need an package to be installed first ?  please let me know
0
 

Author Comment

by:enthuguy
ID: 38161896
I've requested that this question be closed as follows:

Accepted answer: 0 points for enthuguy's comment #37765497

for the following reason:

Not received additional info
0
 
LVL 30

Expert Comment

by:serialband
ID: 38160403
There's mtail, which adds ansi coloring to log file terms and can be modified to produce exactly what you need.

http://matt.immute.net/src/mtail/
0
 
LVL 35

Expert Comment

by:Duncan Roe
ID: 38161897
@enthuguy: what extra information were you waiting for? Ozo posted a Perl script - you will have Perl on your system. I tried a variant of his script and it worked fine
09:31:26$ cat ee90.pl
#!/usr/bin/perl
require Term::Cap;
my $term = Tgetent Term::Cap { TERM => undef, OSPEED => $ospeed };
my $so = $term->Tputs('so');
my $se = $term->Tputs('se');
open T,'tail --follow=name /var/log/debug|' or die $!;
$|=1;
while( <T> ){
    s/(MARK|error)/$so$1$se/g;
    print;
}

Open in new window

Substitute your file for /var/log/debug and your words of interest for MARK|error (any number of words, separated by bar characters)
0
 
LVL 35

Expert Comment

by:Duncan Roe
ID: 38165061
I suggest split points between ozo http:#a37763873 and duncan_roe http:#a38161897. Ozo's post defined the basic mechanism but without sufficient instructions for enthuguy to understand how to use it - duncan_roe provided these instructions.
0

Featured Post

Will your db performance match your db growth?

In Percona’s white paper “Performance at Scale: Keeping Your Database on Its Toes,” we take a high-level approach to what you need to think about when planning for database scalability.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Setting up Secure Ubuntu server on VMware 1.      Insert the Ubuntu Server distribution CD or attach the ISO of the CD which is in the “Datastore”. Note that it is important to install the x64 edition on servers, not the X86 editions. 2.      Power on th…
In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (http://dilbert.com/strips/comic/2007-08…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
Six Sigma Control Plans
Suggested Courses

656 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question