1. added grepdbg program (so you can search your debug files and get times
[spider.git] / perl / grepdbg
1 #!/usr/bin/perl
2 #
3 # Program to do a grep with dates and times on the debug
4 # files
5 #
6 # dispdbg [-nnn ...] <string>
7 #
8 # the -nnn is the day you what to look at -1 is yesterday -0 is today
9 # and is optional if there is only one argument
10 # <string> is the string, a caseless search is done
11 #
12 #
13
14 require 5.004;
15
16 # search local then perl directories
17 BEGIN {
18         # root of directory tree for this system
19         $root = "/spider"; 
20         $root = $ENV{'DXSPIDER_ROOT'} if $ENV{'DXSPIDER_ROOT'};
21         
22         unshift @INC, "$root/perl";     # this IS the right way round!
23         unshift @INC, "$root/local";
24 }
25
26 use DXVars;
27 use DXUtil;
28 use DXLog;
29
30 use strict;
31
32 use vars qw(@list $fp @today $string);
33
34 $fp = DXLog::new('debug', 'dat', 'd');
35 @today = Julian::unixtoj(time()); 
36
37 for my $arg (@ARGV) {
38         if ($arg =~ /^-/) {
39                 $arg =~ s/^-//o;
40                 push @list, $arg;
41         } else {
42                 $string = $arg;
43                 last;
44         }
45 }
46 die "usage: dispdbg [[-nnn] ..] <string>\n" unless  $string;
47
48 push @list, "0" unless @list;
49 for my $entry (@list) {
50         my @now = Julian::sub(@today, $entry); 
51         my $fh = $fp->open(@now); 
52         my $line;
53         if ($fh) {
54                 while (<$fh>) {
55                         my $line = $_;
56                         chomp $line;
57                         if ($line =~ m{\Q$string}io) {
58                                 my @line =  split '\^', $line;
59                                 my $t = shift @line;
60                                 print atime($t), ' ', join('^', @line), "\n"; 
61                         }
62                 }
63                 $fp->close();
64         }
65 }
66 exit(0);