Operating System - HP-UX
1770999 Members
2825 Online
109003 Solutions
New Discussion юеВ

Re: Shell script to calculate time since last file modification

 
SOLVED
Go to solution
ABS_1
Regular Advisor

Shell script to calculate time since last file modification

Does anyone have a shell script that will output the time (in seconds) that has elapsed since the last modification of a file? Basically, I need to email if a file has not been modified since x seconds.
7 REPLIES 7
Sanjay_6
Honored Contributor

Re: Shell script to calculate time since last file modification

Hi,

A coupld of ways listed here,

http://forums1.itrc.hp.com/service/forums/questionanswer.do?threadId=105260

Hope this helps.

regds
Hein van den Heuvel
Honored Contributor

Re: Shell script to calculate time since last file modification


Why not turn it around.

'touch -t' a reference file with that target time.

next 'find -newer ...'


hth,
Hein.
Rodney Hills
Honored Contributor
Solution

Re: Shell script to calculate time since last file modification

Using perl, -M returns age of a file as a number of days and partial day. So you could do the following-

perl -e 'print 24*60*60*(-M $ARGV[0])' afile

HTH

-- Rod Hills
There be dragons...
ABS_1
Regular Advisor

Re: Shell script to calculate time since last file modification

Hi ROdney,

Thanks for the one liner. That will do the trick. By the way, doing a man on Perl does not explain the -M option, where would this option be described (new to Perl...). Thanks so much!
Rodney Hills
Honored Contributor

Re: Shell script to calculate time since last file modification

If you have a full install of perl, then you could do a "man perlfunc" for perl functions.

Usually stored under /opt/perl.

HTH

-- Rod Hills
There be dragons...
ABS_1
Regular Advisor

Re: Shell script to calculate time since last file modification

man on perlfunc comes back with nothing. I guess I don't have the full version installed. Anywhere else (perhaps online)?
Sanjay_6
Honored Contributor

Re: Shell script to calculate time since last file modification