[prev in list] [next in list] [prev in thread] [next in thread]
List: aix-l
Subject: Re: Determining how many seconds ago a file has been touched
From: "Mills, John T" <John.Mills () GRAYBAR ! COM>
Date: 2009-07-31 12:19:14
Message-ID: ADC0BBEE2BA21645982922CCF8C7AD2702F4F08B () SEBEV1PW ! graybar ! com
[Download RAW message or body]
I extended one of my KSH scripts with embedded perl. Perl has about 10 states of a \
file that it can delve and it has the ability to convert epoch to a readable format.
CTIME = creation time in seconds since epoch
MTIME = last touch time in seconds since epoch
STIME = creation time in human readable
ETIME = last touch time in human readable
TTIME = length of time between creation and last touch in seconds
CTIME=`perl -e ' @stats = stat("@ARGV"); print @stats[8];' $FILE`
MTIME=`perl -e ' @stats = stat("@ARGV"); print @stats[10];' $FILE`
STIME=`perl -e 'use Time::Local; $tm_TIME=localtime("@ARGV"); printf $tm_TIME;' \
$CTIME | awk {'print $2 "-" $3 "," $4'}` ETIME=`perl -e 'use Time::Local; \
$tm_TIME=localtime("@ARGV"); printf $tm_TIME;' $MTIME | awk {'print $2 "-" $3 "," \
$4'}` let TTIME=$MTIME-$CTIME
John T Mills
-----Original Message-----
From: IBM AIX Discussion List [mailto:aix-l@Princeton.EDU] On Behalf Of Jean-Marc \
Monnez
Sent: Friday, July 31, 2009 6:09 AM
To: aix-l@Princeton.EDU
Subject: Re: Determining how many seconds ago a file has been touched
Hello Holger,
I met the same problem as yours.
My solution was a new command FileAge I wrote in C.
Usage: FileAge file
#include <stdio.h>
#include <sys/time.h>
#include <sys/stat.h>
#include <unistd.h>
#include <errno.h>
int main (int argc , char **argv)
{
struct stat st;
struct timestruc_t time_pointer;
if (stat(argv[1], &st) != 0)
{
fprintf(stderr, "%s: No access to %s\n", argv[0], argv[1]);
exit(1);
}
gettimer(TIMEOFDAY, &time_pointer);
printf("%d\n", (int)time_pointer.tv_sec - st.st_mtime);
exit(0);
}
Hope it can help you.
Regards.
-- JMM
-----------------------------
Jean-Marc MONNEZ
MSA / AGORA / Editique
monnez.jean-marc@agora.msa.fr
-----------------------------
Holger van Koll a écrit :
> Hello,
>
> how can I determine how many seconds ago a file has been touched?
>
> I need to put the time in seconds into a (ksh)-variable. I looked at
> ls/find but did not see any possibility.
>
> Regs, Holger
>
>
Ce message est protégé par les règles relatives au secret des correspondances. Il est \
donc établi à destination exclusive de son destinataire. Celui-ci peut donc contenir \
des informations confidentielles. La divulgation de ces informations est à ce titre \
rigoureusement interdite. Si vous avez reçu ce message par erreur, merci de le \
renvoyer à l'expéditeur dont l'adresse e-mail figure ci-dessus et de détruire le \
message ainsi que toute pièce jointe.
This message is protected by the secrecy of correspondence rules. Therefore, this \
message is intended solely for the attention of the addressee. This message may \
contain privileged or confidential information, as such the disclosure of these \
informations is strictly forbidden. If, by mistake, you have received this message, \
please return this message to the addressser whose e-mail address is written above \
and destroy this message and all files attached.
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic