Time stamp calculation

Hi all;

I'm relatively new to scripting,I am working on a monitoring script.....where in i have to write subroutine

which does the follows:

It will check the time stamp of a file ( Oracle remarchive files) and compare it with existing time.If the time difference happen to be more than 90 minutes it needs to probably report the presence of this file to the administrator.(by design i mean where i work this files are gunzipped and moved to a different location or a tape before 90 minutes) so the threshold is 90 minutes

I have tried something like

a=`ls -lrt $1|awk {'print $8'}`
b=`date +%s`
c=`date -d "$a" +%s`
diff1=`expr $b - $c`
diff2=`expr $diff1 / 60`
diff3=`expr $diff2 / 60`
date -d '1970-01-01 UTC $diff1 seconds' +"%a %b %d %T %Z %Y"

How ever iam not able to proceed from here.

Is there any method where in i can take for example 00:00 hrs as refrence and calculate seconds since then instead of default 1970-01-01.

Any input will be highly appreciated,thanks in advance.

Regards,
Maverick

if you have Python, here's an alternative solution

#!/usr/bin/env python
import os
import time
import smtplib
# email options
SERVER = "localhost"
FROM = "root@example.com"
TO = ["root"] 
SUBJECT = "Alert!"

#main
numberminutes = 60*90
now = time.time()
filetomonitor = os.path.join("/home","path1","path2","filename")
timestamp = os.path.getmtime( filetomonitor )
if now-numberminutes > timestamp: #more than 90minutes
    #send email
    TEXT= "send alert: have not update for more than 90 minutes"
    message = """\
From: %s
To: %s
Subject: %s

%s
""" % (FROM, ", ".join(TO), SUBJECT, TEXT)

    server = smtplib.SMTP(SERVER)
    server.sendmail(FROM, TO, message)
    server.quit()

Hi,

Thanks you for the update.I will definitely try it.:slight_smile:

Well,is there as way we can do it in shell,only a hint would be fine.....

you can use the find command , -mtime might be a possible option.

you may want to touch a file 90 min ago from now

touch -t 200905162340 file

then use

find . -type f -name "filename" -newer file -print 

also explore the option mmin of find command.

Hi all;

Thank you all for your valuable inputs,finally as you all suggested i have tried

find ~ -mmin -90 \! -type d -exec ls -l {} \;

and it has solved my issue.

Regards,
Maverick