Time stamp calculation


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Time stamp calculation
# 1  
Old 05-16-2009
Lightbulb 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

Last edited by maverick_here; 05-16-2009 at 02:31 AM.. Reason: editing
# 2  
Old 05-16-2009
if you have Python, here's an alternative solution
Code:
#!/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()

# 3  
Old 05-16-2009
Thank you

Hi,

Thanks you for the update.I will definitely try it.Smilie
# 4  
Old 05-16-2009
Well,is there as way we can do it in shell,only a hint would be fine.....
# 5  
Old 05-16-2009
you can use the find command , -mtime might be a possible option.
# 6  
Old 05-16-2009
you may want to touch a file 90 min ago from now

Code:
touch -t 200905162340 file

then use

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


also explore the option mmin of find command.
# 7  
Old 05-17-2009
Thank you

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
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Time calculation

Hi Gurus, I need to get one hour before time is yyyymmddhh format. ex. date +"%Y%m%d%H" gives 2017052814 but I need 2017052813 Thankx Please use CODE tags as required by forum rules! (6 Replies)
Discussion started by: nalakaatslt
6 Replies

2. UNIX for Advanced & Expert Users

Need mtime with time stamp

hi all find /folder1 -mtime 1 >folder1 with the above command , I can get the output of all the files which are modified(within folders and sub folders of folder1) in the last 24 hours. but the listed files output , does not contain the time stamp with it. I request you to give... (4 Replies)
Discussion started by: sidharthmellam
4 Replies

3. Solaris

System time and Cron time stamp not matching

On Solaris 10 server the system date won't match with the timestamp on files created by a cron jobs, Please help here is what i get when i check for system date infodba-ie10ux014:/tcpdv1_ie10/tcadmin/bin\n\r-> date Tue Apr 24 15:27:43 GMT 2012at same time i executed a cron job, and checked... (4 Replies)
Discussion started by: karghum
4 Replies

4. Shell Programming and Scripting

How to get time duration between two human readable time stamp in Unix?

Here is two time I have: Jul 12 16:02:01 Jul 13 01:02:01 and how can I do a simple match to get difference between two time which is 09:00:00 Thanks in advance. (3 Replies)
Discussion started by: ford99
3 Replies

5. Shell Programming and Scripting

regarding time stamp

hi everyone i am facing a strange problem here suppose content of my file is a=1,2,3 b=2,3,4 c=4,5,6 time= now the problem is i want to add value in front of time variable and the value should be i format only "HHMMSS" so it should be like this a=1,2,3 b=2,3,4 c=4,5,6... (3 Replies)
Discussion started by: aishsimplesweet
3 Replies

6. UNIX for Dummies Questions & Answers

Time Calculation

I have a file with over 100,000 lines of data with looking to compare times of about 2000 lines to get a total time of a process. The lines of unique data are as follows. FINER: CacSoapServer:reserveNetworkResource got the sessionID and INFO: Created CAC session ID The command... (5 Replies)
Discussion started by: bpfoster76
5 Replies

7. Shell Programming and Scripting

Time difference calculation

Hi Team, I am currently in the process of writing a script which will take a filename in the format SKADEV.0.db2.NODE0000.CATN0000.20080714231015.001 where the sixth string(with "." as the seperator) is the time stamp of the time of creation of the file. now here is my issue . I need to be... (2 Replies)
Discussion started by: Segwar
2 Replies

8. UNIX for Dummies Questions & Answers

checking time stamp

Hi, I am having a script in which I am again calling a script, but before calling that script I need to perform a time check (say 1 - 2 am i.e. I would be able to call that script if time is between 1:00 am and 2:00 am) but this time stamp needs to be configurable. can anybody suggest me how... (7 Replies)
Discussion started by: Manvar Khan
7 Replies

9. UNIX for Dummies Questions & Answers

capturing the time stamp

Hi All, I am working on a korn shell script. i have a file such as: DS.PETSCO.20060601203514.20060531.ctl_20060717124431 i have 2 problems here. 1) i have to capture the time stamp from the above file i.e this number 20060717124431. format of time stamp is YYYYMMDDHHMMSS. can... (4 Replies)
Discussion started by: pavan_test
4 Replies

10. UNIX for Advanced & Expert Users

time calculation

Hi, I have start time as a string like 06:04:01 and end time like 06:05:01 i need do a simple math to get the duration. What is the best way to do this in Korn Shell scripting? Thanks (2 Replies)
Discussion started by: liux99
2 Replies
Login or Register to Ask a Question