Tail-Problem
Florian Lohoff
flo at mini.gt.owl.de
Mon Dec 14 11:48:59 CET 1998
On Sun, Dec 13, 1998 at 06:30:11PM +0100, Alexander Reelsen wrote:
> Moin
>
> Ich werde jetzt kein tail neuinstallieren und da ich von diesen buffered
> Sachen auch nich so die ahnung habe, nehm ich ab jetzt nen perl einzeiler.
> Hier fuer alle, die sich nicht mit grep abmuehen moechten :-):
> tail -f /var/log/daemon.log | perl -e 'while (<STDIN>) { print
> if ( (/bla/) && (/blupp/) ) }'
>
> P.S. Mal gespannt bei wem DAS nicht geht. ;-)
>
> MfG, Alexander
Komplett in perl loesung ...
#!/usr/bin/perl
sub tailf {
my ($buffer, $rr, $count);
while() {
# Is there a complete line in filebuffer (\n at end)
# Return line if found, and delete from filebuffer
if ($tailfbuf =~ s/^(.*\n)//) {
return $1;
}
# Read a maximum of 4096 bytes from logfile
$rr=sysread(infile,$buffer,4096);
# If more the 0 bytes got read append to filebuffer
if ($rr > 0) {
$tailfbuf.=$buffer;
next;
}
# Wait 1/3 of a second
select(undef,undef,undef,0.33);
}
}
open(infile,$ARGV[0]);
seek(infile,0,2);
while($line=tailf()) {
if ($line =~ /bla/ && $line =~ /blubb/) {
print $line;
}
}
Flo
--
Florian Lohoff flo at mini.gt.owl.de +49-5241-470566
Good, Fast, Cheap: Pick any two (you can't have all three). (RFC 1925)
Look at http://www.linux-magazin.de/cluster this comes quite close.
More information about the Linux
mailing list