これは、問題に対する私自身の強力な解決策です(進行中の作業)。貢献してくれたすべての人に感謝します。
#!/usr/bin/env perl
# This script checks if all input date values have a delta of
# say, 5 minutes to the previous date value.
#
# $Id: test_datetintervals.t 1804 2012-08-07 10:35:48Z knb $
#
# for f in $(ls -1 *std--ytd--2012-m01*xlsx); do echo ""; echo "$f"; ssgrep 2012- $f | test_datetintervals.t -num 60 -comm "$(basename $f)"; done
#
# ssgrep 2012 Monitoring_DailyAvg.min--2008-01-01--2012-11-01.txt.xlsx | grep -v "2012.15" | ./test_datetintervals.t -num 0 -interval day -pat \'%m/%d/%Y
use Modern::Perl;
use Getopt::Long;
use File::Basename;
use Carp qw (carp croak confess cluck);
use lib '/config';
use lib 'T:';
use lib '/lib/'; # wb3
use Pod::Usage;
use Test::More;
use DateTime;
use DateTime::Format::Strptime;
my $interval = "minute"; # 2012-06-27T23:05:00
my $n = 5;
my $comment = "";
my $help;
my $man;
my $pat = '%FT%T', # 2012-10-09T17:00:00
#my $pat = "'%m/%d/%Y", # 09/27/2012
my $argcnt = scalar(@ARGV);
GetOptions( 'num=i' => \$n, 'interval:s' => \$interval, 'comment:s' => \$comment, 'help|?' => \$help,
man => \$man, 'pattern:s' => \$pat ) or pod2usage(2);
my $fn = basename($0);
my $msg2 = "This script must be part of a unix pipe. Script checks if all input date values have a delta of $n ${interval}s to the previous date value.";
pod2usage(
-message => "$msg2\nCall $fn --man to see full documentation",
-exitstatus => 1
)
if $help;
my $msg = <<'MSG';
# Sample calls:
#
# for f in $(ls -1 *std--ytd--2012.txt.xlsx); do echo ""; echo "$f"; ssgrep 2012- $f | test_datetintervals.t -num 60 -comm "$(basename $f)"; done
#
MSG
pod2usage( -message => "$msg2\n\n$msg", -exitstatus => 0 ) if $man;
pod2usage( -message => "# \n!!!! Script was called with no arguments- but this cannot work.\n\n $msg2\n\n$msg", -exitstatus => 0 ) if $argcnt == 0;
my $Strp = new DateTime::Format::Strptime(
pattern => $pat,
locale => 'de_DE',
time_zone => 'floating',
on_error => \&my_carp
);
note($msg2);
my $line;
my $prev;
my $okflag = 1;
my $i = 0;
while (<>) {
$line = $_;
chomp $line;
my $dt = $Strp->parse_datetime($line);
if ( !$dt ) {
note "Line $.: cannot parse '$line' to datetime object: $!";
}
if ( !$prev ) {
note "Line $.: previous value not found/not applicable!";
note $dt->datetime();
} else {
my $duration = $dt->delta_ms($prev);
my $diff = $duration->in_units("${interval}s");
if ( $diff != $n ) {
fail( "$.: $n $interval interval between " . $prev->datetime() . " and " . $dt->datetime() );
note "prev: " . $prev->datetime();
note " : " . $dt->datetime();
note "diff: $diff ${interval}s";
note "";
$okflag = 0;
}
$i++;
}
$prev = $dt;
}
if ($okflag){
ok(1, "no gaps of $n ${interval}s detected! $comment");
note "";
}
note("done testing '$comment', about $i lines");
note "";
done_testing();
sub my_carp {
carp " line $.: Something wrong with " . $_;
note $_[1];
return 1; # 0 for continue
}
=pod
usage: $fn.pl [-?] [long options...]
-? --usage --help Prints this usage information.
--man
--num=i # 5
--interval # minutes
--comment
--pattern #'%FT%T', # 2012-10-09T17:00:00
--overwrite (or nooverwrite)
=cut