From owner-freebsd-questions@FreeBSD.ORG Fri Aug 22 15:26:24 2008 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 35A4F1065674 for ; Fri, 22 Aug 2008 15:26:24 +0000 (UTC) (envelope-from steve@ibctech.ca) Received: from ibctech.ca (v6.ibctech.ca [IPv6:2607:f118::b6]) by mx1.freebsd.org (Postfix) with SMTP id DB53E8FC12 for ; Fri, 22 Aug 2008 15:26:23 +0000 (UTC) (envelope-from steve@ibctech.ca) Received: (qmail 66276 invoked by uid 89); 22 Aug 2008 15:34:00 -0000 Received: from unknown (HELO ?IPv6:2607:f118::5?) (steve@ibctech.ca@2607:f118::5) by 2607:f118::b6 with ESMTPA; 22 Aug 2008 15:34:00 -0000 Message-ID: <48AEDAFA.1010905@ibctech.ca> Date: Fri, 22 Aug 2008 11:27:54 -0400 From: Steve Bertrand User-Agent: Thunderbird 2.0.0.16 (Windows/20080708) MIME-Version: 1.0 To: DAve References: <48AECD11.1000705@pixelhammer.com> In-Reply-To: <48AECD11.1000705@pixelhammer.com> X-Enigmail-Version: 0.95.6 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Cc: 'User Questions' Subject: Re: Tailing logs X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 22 Aug 2008 15:26:24 -0000 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 () { 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@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@mail.gmail.com> for iaccounts@ibctech.ca:58 **** Aug 22 11:31:46 pearl vpopmail[66048]: vchkpw-submission: (CRAM-MD5) login success steve@ibctech.ca:2607_f118__5 **** Aug 22 11:31:56 pearl spamd[95770]: prefork: child states: II