我认为我有这个工作,作为我的实际问题的轻微变化:
#!/usr/bin/perl -s
use Time::Local;
$OUT = `tail -500 /log/out.log | grep ^TRX | tail -1 | cut -c46-62`;
$GET = `tail -500 /log/get.log | grep ^PROC | tail -1 | cut -c28-45`;
my $Start = getDate($OUT);
my $Finish = getDate($GET);
$DiffS = ( $Finish - $Start );
$DiffM = ( $Finish - $Start ) / 60;
print "$DiffS\n";
exit($DiffS);
sub getDate {
$Y = substr $_[0], 0, 4;
$M = substr $_[0], 4, 2;
$D = substr $_[0], 6, 2;
$h = substr $_[0], 9, 2;
$m = substr $_[0], 11, 2;
$s = substr $_[0], 13, 2;
return timelocal($s,$m,$h,$D,$M,$Y);
}
虽然这不是我所要求的,但它允许我给出一个差异,我可以在已经设置为的 shell 脚本中使用它if $I > $Diff then DO MAGICALLY THINGS
#!/bin/ksh
result=$(/usr/bin/logDiff)
print $result
if $result > 60
...