1753481 Members
4483 Online
108794 Solutions
New Discussion

Re: data archive

 
SOLVED
Go to solution
James R. Ferguson
Acclaimed Contributor

Re: data archive

Hi (again):

OK, so you want to examine the last modification timestamp of a directory and deduce the date 6-months ago, adjusted for year boundries. Use Perl:

# cat ./sixago
#!/usr/bin/perl
use strict;
use warnings;
use Time::Local;
my $dir = shift;
die "$0: directory expected\n" unless -d $dir;
my $moddate = ( stat($dir) )[9];
my ( $sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst )
= localtime($moddate);
my $modtime = timelocal( 0, 0, 0, 15, $mon, $year ) - ( 180 * 86400 );
print join " ", ( split / /, localtime($modtime) )[ 1, 4 ], "\n";
1;

...run as:

# ./sixago /directory

For example:

# touch 02290800 /tmp/mydir
# ./sixago /tmp/mydir
Aug 2007

# touch /tmp/mydir
# ./sixago /tmp/mydir
Jun 2008

This works by fetching the last modification time (in seconds) for the directory. This is converted into a month-day-year-time format. The month and year are used and the day of the month set to 15. This modified date is then converted back to Epoch seconds and 180-days worth of seconds (one day = 86400 seconds) are subtracted. The new date in seconds is then converted to a month-day-year-time format and the local month name and year are extracted and returned.

Regards!

...JRF...
James R. Ferguson
Acclaimed Contributor

Re: data archive

Hi (again):

...and to use the Perl script and return the date to your shell script, simply do:

...

./archive_tool $(./sixago /somedirectory)

or:

ARCHDATE=$(./sixago /somedirectory)

Regards!

...JRF...