Adding log extractor

This commit is contained in:
John Poole 2026-06-04 21:26:54 -07:00
commit 0905c57bc1

View file

@ -0,0 +1,51 @@
#!/usr/bin/env perl
#
# $Id$
# $HeadURL$
#
# Example:
# ./extract_tbeam_log_segment.pl DAN_raw_20260604_094435.log 20260604_211500 20260604_211900
#
# Redirect example:
# ./extract_tbeam_log_segment.pl DAN_raw_20260604_094435.log 20260604_211500 20260604_211900 \
# > DAN_segment_20260604_211500_211900.log
#
use strict;
use warnings;
my $LOGDIR = "/home/jlpoole/logs";
my ($logname, $start, $end) = @ARGV;
die "Usage: $0 LOGNAME START_TIME END_TIME\n"
unless defined $logname && defined $start && defined $end;
die "START_TIME must look like YYYYMMDD_HHMMSS or YYYYMMDD_HHMMSS.xxx\n"
unless $start =~ /^\d{8}_\d{6}(?:\.\d+)?$/;
die "END_TIME must look like YYYYMMDD_HHMMSS or YYYYMMDD_HHMMSS.xxx\n"
unless $end =~ /^\d{8}_\d{6}(?:\.\d+)?$/;
die "END_TIME must be greater than START_TIME\n"
unless $end gt $start;
my $path = "$LOGDIR/$logname";
open my $fh, '<', $path
or die "Cannot open $path: $!\n";
while (my $line = <$fh>) {
my ($stamp) = split /\s+/, $line, 2;
next unless defined $stamp;
next unless $stamp =~ /^\d{8}_\d{6}(?:\.\d+)?$/;
# Include start time, exclude end time.
print $line if $stamp ge $start && $stamp lt $end;
# Optional early exit because logs are chronological.
last if $stamp ge $end;
}
close $fh;