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
22 # search local then perl directories
24 # root of directory tree for this system
26 $root = $ENV{'DXSPIDER_ROOT'} if $ENV{'DXSPIDER_ROOT'};
28 unshift @INC, "$root/perl"; # this IS the right way round!
29 unshift @INC, "$root/local";
39 use vars qw(@list $fp $today $string);
42 $fp = DXLog::new('debug', 'dat', 'd');
43 $today = $fp->unixtoj(time());
50 if ($arg =~ /^\s*\-+(?:[h\?]e?l?p?)/) {
55 } elsif ($arg =~ /^\d+$/) {
65 push @list, "0" unless @list;
66 for my $entry (@list) {
67 my $now = $today->sub($entry);
68 my $fh = $fp->open($now);
83 shift @prev while @prev > $nolines;
84 if ($line =~ m{$string}io) {
86 s/([\x00-\x1f\x7f-\xff])/sprintf("\\x%02X", ord($1))/eg;
87 my ($t, $l) = split /\^/, $_, 2;
88 print atime($t), ' ', $l, "\n";
96 die "usage: grepdbg [nn] [[-nnn] ..] <regexp>\n";