Hi
I am currently using perl to look at time difference f.ex between files.
But due to a monitoring tool I need to convert them into simple shell
The only thing this scripts does is to turn a date into secounds from 1970, is there any one that knows a way to do this in sh.
What I need is the ability to convert different types of timestamps into secounds.
Hope someone can help.
/Lhg
I am currently using perl to look at time difference f.ex between files.
But due to a monitoring tool I need to convert them into simple shell
The only thing this scripts does is to turn a date into secounds from 1970, is there any one that knows a way to do this in sh.
What I need is the ability to convert different types of timestamps into secounds.
Code:
# TimeDiff.pl '2004 Mar 22 15:00' '22032004-14:00'
$Var1 = "$ARGV[0]\n";
@TmpArrayTid1 = split /\s|:/, $Var1;
#@TmpArray vil så se sådan ud: (Mar,22,11,27)
#print "$TmpArrayTid1[0]\n";
# TmpArrayTid1 0=Year 1=Mrd 2=Day 3=Hour 4=Min
$Var2 = "$ARGV[1]\n";
$Var2 =~ /(\d{2})(\d{2})(\d{4})-(\d{2}):(\d{2})/;
#print "$1\n";
# $1=day $2=mrd $3=Year $4=hour $5=Min
# Mar 22 12:32 2004
$Mdr = {
'Jan' => 1,
'Feb' => 2,
'Mar' => 3,
'Apr' => 4,
'May' => 5,
'Jun' => 6,
'Jul' => 7,
'Aug' => 8,
'Sep' => 9,
'Oct' => 10,
'Nov' => 11,
'Dec' => 12,
};
#print "Month number for February is $Mdr->{("$TmpArrayTid1[1]")}\n";
use Time::Local;
#Converts a date into EPOCH:
# 2004 Mar 22 15:17 # "$TmpArrayTid1[0]\n" 0=Year 1=Mrd 2=Day 3=Hour 4=Min
$sec = "0";
$min = "$TmpArrayTid1[4]\n";
$hour = "$TmpArrayTid1[3]\n";
$day = "$TmpArrayTid1[2]\n";
$mon = $Mdr->{("$TmpArrayTid1[1]")};
# print "$mon\n";
$year = "$TmpArrayTid1[0]\n";
$RunEPOCH = timelocal($sec,$min,$hour,$day,($mon-1),($year-1900));
#print "RunEpoch =\t [$RunEPOCH]\n";
#Converts a date into EPOCH:
# 22032004-11:23 $1=day $2=mrd $3=Year $4=hour $5=Min
$sec = "0";
$min = "$5\n";
$hour = "$4\n";
$day = "$1\n";
$mon = "$2\n";
# print "$mon\n";
$year = "$3\n";
$EpochSec = timelocal($sec,$min,$hour,$day,($mon-1),($year-1900));
#print "DateEpoch =\t [$EpochSec]\n";
#Finds diff. between the 2 Epoch sekund vars:
$Diff = (($RunEPOCH - $EpochSec) / 60 );
print "$Diff\n";
Hope someone can help.
/Lhg