I'm writing a routine to provide uptime for our systems. The data is stored as a number of files in /var/adm/uptime which look like
These files are created at boot time by a line in inittab which looks like
and the 'current' one is touched every minute to modify the last update time. From this it's pretty trivial to report on uptime using a simple report like
Now comes the question - management wants a report on uptime during a certain time period. To do this I need to convert start and end date paramters into seconds since the epoch. I've searched on CPAN and come up with Date::Manip but it looks like a hammer to crack a nut - even the author says that it shouldn't be used most of the time.
Can anyone recommend a simple way of converting YY/MM/DD to seconds since the epoch?
Ceci n'est pas une signature
Columb Healy
Code:
-rw-r--r-- 1 root system 0 Aug 31 08:27 1188566501
-rw-r--r-- 1 root system 0 Aug 31 08:39 1188567143
-rw-r--r-- 1 root system 0 Sep 03 04:57 1188567905
-rw-r--r-- 1 root system 0 Sep 03 05:30 1188813780
Code:
uptime:23456789:wait:touch /var/adm/uptime/$(perl -e 'print time')
Code:
#!/usr/bin/perl -w
use strict;
foreach my $file ( glob "/var/adm/uptime/[0-9]*" )
{
$file =~ m!.*/(.*)! and my $start = $1;
my $end = +(stat $file)[9];
print "Up between ", (scalar localtime $start), " and ", (scalar localtime $end), "\n";
}
Can anyone recommend a simple way of converting YY/MM/DD to seconds since the epoch?
Ceci n'est pas une signature
Columb Healy