LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 06-10-2004, 04:23 AM   #1
d1s4st3r
Member
 
Registered: May 2004
Location: Italy
Posts: 70

Rep: Reputation: 16
Coloring real-time logs on tty


Hi everyone,
I just added this line to my "/etc/syslog.conf":
Code:
*.*        /dev/tty12
to have real-time logs printed on tty12.
The only terminals I can log in are tty[1-6] + tty7 for X, but that's ok.
Well, now I'd like to have many different colors (maybe using escape sequences) for the various types of log messages (eg: all kernel messages in green, all ACPI messages in yellow, all login failures in red, and so on) directly on the tty12, but I don't know how can I do this.
I thought I could write a Bash script which reads each line added on tty12, uses grep to discover the type of message, then colors it (using echo and redirection), but I couldn't find a way to read the data printed on tty12.
Code:
cat /dev/tty
Code:
tee /dev/tty12
these commands don't work.
I think it's very useful to have different colors instead of all-grey log messages, but what's the way to do this?
Thanks to all you people!
Bye!
 
Old 06-10-2004, 07:21 AM   #2
Donboy
Member
 
Registered: Aug 2003
Location: Little Rock, Arkansas
Distribution: RH, Fedora, Suse, AIX
Posts: 736

Rep: Reputation: 31
Here's a little gem I picked up from Linux Server Hacks. Excellent book, BTW... I highly recommend it.

This is a Perl script that will color text in the shell. Save this as "rcg" and put it somewhere in your path.

Code:
#!/usr/bin/perl

use strict;
use Term::ANSIColor qw(:constants);

my %target = ( );

while (my $arg = shift) {
  my $clr = shift;

  if(($arg =~ /^-/) | (!$clr)) {
    print "Usage: rcg [regex] [color] [regex] [color] ...\n";
    exit;
  }
  $target{$arg} = eval($clr);
}

my $rst = RESET;

while(<>) {
  foreach my $x (keys(%target)) {
    s/($x)/$target{$x}$1$rst/g;
  }
  print;
}
Usage is like this...

Code:
tail -50 /var/log/messages | rcg kernel GREEN error RED
 
Old 06-10-2004, 10:18 AM   #3
d1s4st3r
Member
 
Registered: May 2004
Location: Italy
Posts: 70

Original Poster
Rep: Reputation: 16
Fantastic!!!
Thanx very much!
I tried it out and it works fine, but what can I do now to have the new colored logs always directed on tty12 (expecially each time they're updated, always with colors)?
I mean... should I write I kind of deamon that listens for every new log from the kernel, then colors it, then sends it to tty12 appending to the other ones before?
The only problem is that I *really* don't know how to capture new logs appended each time on tty12, because I don't know how to have that "writings" printed on the console I'm currently working on (one of tty[1-6]).
If I could read those message on my console, I could simply use "cat" to read it, send it to "rcg.perl", then send it back again to /dev/tty12, but colored this time!
BTW, I thank you very much and I'll try until I find a way!
Bye!
 
Old 06-10-2004, 11:27 AM   #4
Donboy
Member
 
Registered: Aug 2003
Location: Little Rock, Arkansas
Distribution: RH, Fedora, Suse, AIX
Posts: 736

Rep: Reputation: 31
Hmmm... hard to say. Maybe somebody here knows more about working with TTY's than me. Personally, I would just login to the server from that console and run your commands piped through the rcg program. I do this myself all the time. I login with SSH and run the command just like I'm showing above. Actually, for some commands that I use more often, I just put them into my .bashrc file as an alias so the rcg program gets called everytime.
 
Old 09-03-2004, 05:40 PM   #5
d1s4st3r
Member
 
Registered: May 2004
Location: Italy
Posts: 70

Original Poster
Rep: Reputation: 16
Just tried out this cool program: "ccze".
I found it in Debian Sid repositories thru APT (section "utils") and it colors out any kind of log files (exim, apache, syslog, ecc...), and it has much more interesting features.
Cool!
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How can I log every time a certain user logs in? uman Linux - Security 1 12-27-2004 03:07 PM
3D acceleration same time with tty jaakkop Linux - Hardware 2 10-17-2004 07:20 AM
real-time OS h/w Programming 11 01-24-2004 08:28 PM
Real-Time programming javpogon Programming 5 09-04-2003 08:25 AM
Real Time Plot... DaFrEQ Linux - Software 0 08-27-2002 08:25 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 10:47 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration