3 # Program to do a grep with dates and times on the debug
6 # grepdbg [nn] [-mm] <regular expression>
9 # nn - is the day you what to look at: 1 is yesterday, 0 is today
10 # and is optional if there is only one argument
12 # -mmm - print the mmm lines before the match. So -10 will print
13 # ten lines including the line matching the regular expression.
15 # <regexp> is the regular expression you are searching for,
16 # a caseless search is done
25 # search local then perl directories
27 # root of directory tree for this system
29 $root = $ENV{'DXSPIDER_ROOT'} if $ENV{'DXSPIDER_ROOT'};
31 unshift @INC, "$root/perl"; # this IS the right way round!
32 unshift @INC, "$root/local";
44 use vars qw(@list $fp $today $string);
46 $fp = DXLog::new('debug', 'dat', 'd');
47 $today = $fp->unixtoj(time());
55 } elsif ($arg =~ /^\d+$/) {
62 die "usage: grepdbg [nn] [[-nnn] ..] <regexp>\n" unless $string;
64 push @list, "0" unless @list;
65 for my $entry (@list) {
66 my $now = $today->sub($entry);
67 my $fh = $fp->open($now);
74 shift @prev while @prev > $nolines;
75 if ($line =~ m{$string}io) {
77 s/([\x00-\x1f\x7f-\xff])/sprintf("\\x%02X", ord($1))/eg;
78 my ($t, $l) = split /\^/, $_, 2;
79 print atime($t), ' ', $l, "\n";