spider/perl/watchdbg
2000-10-31 17:21:53 +00:00

76 lines
1.5 KiB
Perl
Executable File

#!/usr/bin/perl
#
# watch the end of the current debug file (like tail -f) applying
# any regexes supplied on the command line.
#
# examples:-
#
# watchdbg g1tlh # watch everything g1tlh does
# watchdbg gb7baa gb7djk # watch the conversation between BAA and DJK
#
require 5.004;
# search local then perl directories
BEGIN {
# root of directory tree for this system
$root = "/spider";
$root = $ENV{'DXSPIDER_ROOT'} if $ENV{'DXSPIDER_ROOT'};
unshift @INC, "$root/perl"; # this IS the right way round!
unshift @INC, "$root/local";
}
use IO::File;
use DXVars;
use DXUtil;
use DXLog;
use strict;
my $fp = DXLog::new('debug', 'dat', 'd');
my @today = Julian::unixtoj(time());
my $fh = $fp->open(@today) or die $!;
my $exp = join '|', @ARGV;
# seek to end of file
$fh->seek(0, 2);
for (;;) {
my $line = <$fh>;
if ($line) {
if ($exp) {
printit($line) if $line =~ m{(?:$exp)}oi;
} else {
printit($line);
}
} else {
sleep(1);
# check that the debug hasn't rolled over to next day
# open it if it has
my @now = Julian::unixtoj(time());
if ($today[1] != $now[1]) {
$fp->close;
my $i;
for ($i = 0; $i < 20; $i++) {
last if $fh = $fp->open(@now);
sleep 5;
}
die $! if $i >= 20;
@today = @now;
}
}
}
sub printit
{
my $line = shift;
my @line = split '\^', $line;
my $t = shift @line;
my ($sec,$min,$hour) = gmtime((defined $t) ? $t : time);
my $buf = sprintf "%02d:%02d:%02d", $hour, $min, $sec;
print $buf, ' ', join('^', @line);
}
exit(0);