1835360 Members
3611 Online
110078 Solutions
New Discussion

Date manipulation

 
rgoud
Occasional Advisor

Date manipulation

Hi list,
I have loaded Perl date manipulation module and using it I am trying to find the difference between the current time and the time when a lock file is created.

It should display in seconds if possible, how will it work?. Idea here is if the lock file is older than an hour, I wan't to remove it.

Thaks in advance
1 REPLY 1
A. Clay Stephenson
Acclaimed Contributor

Re: Date manipulation

First of all, in UNIX, it's not possible to know when a file was created (except by accident); that data is simply not carried in the inode. The ctime field refers not to when a file was created but rather the last time it was chmod'ed. Typically, you look at the modification time. You don't really need the date modules; the built-in stat function will do nicely.

See tthe attachment, fileage.pl. Invode as fileage.pl -u for full usage.

Typically,

fileage.pl -s 3600 mylockfile
STAT=${?}

case ${STAT} in
0) echo "mylockfile has not been changed in 3600 seconds";;
1) echo "mylockfile has been changed in 3600 seconds";;
*) echo "Error; result ${STAT}"
esac
If it ain't broke, I can fix that.