#!/usr/bin/env perl
#
# Name: fileage.pl
#
# Description: 
#
#   Determines the age of a file passed in as the lone argument.
#   The "age" is defined as the time since the last file modification.
#   The age is printed in 4 different unit-formats, which are space-delimited:
#
#   age_in_seconds age_in_minutes age_in_hours age_in_days
#
#   You can use "awk" to grab the format you want, or create your own.
#
# Usage: To get the format in days
#		fileage.pl myfile | awk '{print $4}'
#
#--------------------------------------------------------------------
#                          REVISION HISTORY
#--------------------------------------------------------------------
#  MOD             PR
# LEVEL   DATE   NUMBER  User  Description
# ----- -------- ------  ------ -------------------------------------
#       06/26/98 37054   MSwam  first version
#       05/25/00 37784_03 MSwam change name to fileage.pl
#
#------------------------------------------------------------------------------
#
# verify input argument specifies an existing file
$infile = $ARGV[0];
if (! -e $infile) {
   die "ERROR: File $infile does not exist.\n";
}

# get file modification time
($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,
 $atime,$mtime,$ctime,$blksize,$blocks) = stat($infile);
            
# convert to different units and write out
$age_secs = (time - $mtime);
$age_mins = $age_secs / 60.0;
$age_hours = $age_mins / 60.0;
$age_days = $age_hours / 24.0;
print "$age_secs $age_mins $age_hours $age_days\n";

