3 # watch the end of the current debug file (like tail -f) applying
4 # any regexes supplied on the command line.
8 # watchdbg g1tlh # watch everything g1tlh does
9 # watchdbg 2 PCPROT # watch all PCPROT messages + up to 2 lines before
10 # watchdbg gb7baa gb7djk # watch the conversation between BAA and DJK
15 # search local then perl directories
17 # root of directory tree for this system
19 $root = $ENV{'DXSPIDER_ROOT'} if $ENV{'DXSPIDER_ROOT'};
21 unshift @INC, "$root/perl"; # this IS the right way round!
22 unshift @INC, "$root/local";
33 my $fp = DXLog::new('debug', 'dat', 'd');
34 my $today = $fp->unixtoj(time());
35 my $fh = $fp->open($today) or die $!;
37 $nolines = shift if $ARGV[0] =~ /^-?\d+$/;
38 $nolines = abs $nolines if $nolines < 0;
39 my $exp = join '|', @ARGV;
49 shift @prev while @prev > $nolines;
50 if ($line =~ m{(?:$exp)}oi) {
60 # check that the debug hasn't rolled over to next day
62 my $now = $fp->unixtoj(time());
63 if ($today->cmp($now)) {
66 for ($i = 0; $i < 20; $i++) {
67 last if $fh = $fp->open($now);
81 $line =~ s/([\x00-\x1f\x7f-\xff])/sprintf("\\x%02X", ord($1))/eg;
82 my ($t, $l) = split /\^/, $line, 2;
83 my ($sec,$min,$hour) = gmtime((defined $t) ? $t : time);
84 my $buf = sprintf "%02d:%02d:%02d", $hour, $min, $sec;
86 print $buf, ' ', $l, "\n";