Tailing logs
Steve Bertrand
steve at ibctech.ca
Fri Aug 22 15:26:24 UTC 2008
DAve wrote:
> I would love to have a way to tail a log, like piping to grep, except I
> see every line and the lines I would normally grep for are highlighted.
> That would be cool. Anyone know of a bash command or tool that will do
> this?
>
> Side note, I am tailing sendmail after changes to my outbound queue
> runners. I want to highlight my sm-mta-out lines but still see all lines.
A little late to the party now, but the following Perl script will
'highlight' the lines containing $pattern with a blank line above and
below, surrounded by ****. The lines not matching will be printed
normally. Note, File::Tail must be installed:
#!/usr/bin/perl
# grep.pl
use warnings;
use strict;
use File::Tail;
my $pattern = "submission";
my $log = "/var/log/maillog";
my $ref=tie *FH,"File::Tail",(name=>$log, maxinterval=>3);
while (<FH>) {
if ($_ =~ /$pattern/) {
chop ($_);
print "\n**** $_ ****\n\n";
} else {
print "$_";
}
}
pearl# ./grep.pl
**** Aug 22 11:30:45 pearl vpopmail[65893]: vchkpw-submission:
(CRAM-MD5) login
success steve at ibctech.ca:2607_f118__5 ****
Aug 22 11:31:19 pearl spamd[32860]: spamd: connection from localhost
[127.0.0.1]
at port 57092
Aug 22 11:31:19 pearl spamd[32860]: spamd: processing message
<6e3e383b080822071
4g37a6ee4bu21e99ebc9e123ab7 at mail.gmail.com> for
iaccounts at ibctech.ca:58
**** Aug 22 11:31:46 pearl vpopmail[66048]: vchkpw-submission:
(CRAM-MD5) login success steve at ibctech.ca:2607_f118__5 ****
Aug 22 11:31:56 pearl spamd[95770]: prefork: child states: II
More information about the freebsd-questions
mailing list