2003-07-02 22:33:18 +00:00
|
|
|
#!/usr/bin/env perl
|
|
|
|
|
|
|
|
# $Id$
|
|
|
|
# greplogs - grep logs for a string.
|
|
|
|
|
|
|
|
use strict;
|
|
|
|
use warnings;
|
|
|
|
|
|
|
|
my $html = 0;
|
|
|
|
die unless @ARGV;
|
|
|
|
if ($ARGV[0] eq '-html') {
|
|
|
|
shift;
|
|
|
|
$html = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
my $s = shift; die unless defined $s;
|
|
|
|
|
2003-07-02 22:52:53 +00:00
|
|
|
# if the string to grep for ends with a digit, add a zero-width negative
|
|
|
|
# look-ahead assertion against another digit. e.g., if we are searching for
|
|
|
|
# "wu_12" do not match "wu_125".
|
|
|
|
if ($s =~ /\d$/) {
|
|
|
|
$s .= "(?!\\d)";
|
|
|
|
}
|
|
|
|
|
2003-07-02 22:33:18 +00:00
|
|
|
my $prev_file = '';
|
|
|
|
|
|
|
|
if ($html) { print "<pre>"; }
|
|
|
|
while (<ARGV>) {
|
|
|
|
chomp;
|
|
|
|
if (/$s/) {
|
|
|
|
if ($ARGV ne $prev_file) {
|
|
|
|
$prev_file = $ARGV;
|
|
|
|
if ($html) {
|
|
|
|
print "</pre><h2>$ARGV</h2><pre>";
|
|
|
|
} else {
|
|
|
|
print "\n\n$ARGV:\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
my $n = sprintf("%05d", $.);
|
|
|
|
if ($html) {
|
|
|
|
s%.*debug.*%<font color=grey>$&</font>%i;
|
2003-07-02 22:52:53 +00:00
|
|
|
s%.*(critical|error).*%<font color=red>$&</font>%i;
|
2003-07-02 22:33:18 +00:00
|
|
|
s%$s%<b>$&</b>%g if $s;
|
|
|
|
print "<font size=-1><a name=$. href=show_log.php?f=$ARGV#$.>$n</a></font> $_\n";
|
|
|
|
} else {
|
|
|
|
print " $n: $_\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ($html) { print "</pre>"; }
|