Finding difference in 2 different timestamps


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Finding difference in 2 different timestamps
# 1  
Old 07-18-2013
Finding difference in 2 different timestamps

Legends,

I have a requirement to run the script exactly after one hour of completion of dependent script.
Code:
Eg: Script B should run after one hour on the completion of Script A.

I got the time stamps using following variables. these scripts runs in autosys

Code:
>  DATE=`date +%H:%M`
> JOB=`jobhist act abcjob  |tail -1 | awk '{print $6}'`

> echo $JOB $DATE
03:23 09:54

>  DIFF=`expr $DATE - $JOB`
expr: non-numeric argument

how to get the timestamp difference.
if diff is more than one then run the job, else, wait for one hour.
how to calculate that . please help
# 2  
Old 07-18-2013
Code:
JOB=03:23 
DATE=09:54
JOB_SECS=$(echo $JOB | awk -F":" '{print $1*60+$2}')
DATE_SECS=$(echo $DATE | awk -F":" '{print $1*60+$2}')

DIFF=$((DATE_SECS-JOB_SECS))
if [ $DIFF -ge 60 ]
then
  echo start job B
fi

This User Gave Thanks to krishmaths For This Post:
# 3  
Old 07-18-2013
Quote:
Originally Posted by krishmaths
Code:
JOB=03:23 
DATE=09:54
JOB_SECS=$(echo $JOB | awk -F":" '{print $1*60+$2}')
DATE_SECS=$(echo $DATE | awk -F":" '{print $1*60+$2}')

DIFF=$((DATE_SECS-JOB_SECS))
if [ $DIFF -ge 60 ]
then
  echo start job B
fi

@krishmaths

Code:
if [ $DIFF -ge 60 ]

is it seconds or minutes. because you calculated diff in seconds?
Please explain working too Smilie Smilie
# 4  
Old 07-18-2013
It is calculated in minutes. 09:54 is derived by +%H +%M in your date command.

I'm simply trying to convert hours into minutes (09 * 60) and add minutes portion (+54). This will give the absolute minutes and can be used for finding out the difference.
This User Gave Thanks to krishmaths For This Post:
# 5  
Old 07-18-2013
Thanks krishmaths
it worked.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Finding first difference between two files

Hi! I'd like to know if it is possible for a command to find the first difference between two large files, output that line from both file and stop, so no need to continue after that to save some computation time. I don't think looping through it will be efficient enough but that's the only... (6 Replies)
Discussion started by: Mojing
6 Replies

2. Shell Programming and Scripting

Calculate difference in timestamps based on unique column value

Hi Friends, Require a quick help to write the difference between 2 timestamps based on a unique column value: Input file: 08/23/2012 12:36:09,JOB_5340,08/23/2012 12:36:14,JOB_5340 08/23/2012 12:36:22,JOB_5350,08/23/2012 12:36:26,JOB_5350 08/23/2012 13:08:51,JOB_5360,08/23/2012... (4 Replies)
Discussion started by: asnandhakumar
4 Replies

3. Shell Programming and Scripting

Need help in finding in date difference

Hi, My date is coming as STARTDATE=Sun Jul 15 00:34:23 2012 ENDDATE=Sun Jul 15 00:50:04 2012I want difference between these two dates,anyone's helps will be appriciated. Thanks Prasoon (3 Replies)
Discussion started by: prasson_ibm
3 Replies

4. Shell Programming and Scripting

finding difference between two files

Hi, I have two files one with 12486 lines second one with 13116 As per the comparsion between two files the count have 630 difference I used diff command to find the difference between two files but it's not understandable could any one suggest any command to get 630 records in a new... (4 Replies)
Discussion started by: thelakbe
4 Replies

5. AIX

How to find time difference between 2 timestamps?

HI All, can some one please help me how to fine the difference between two time stamps say a= Nov 10, 2009 9:21:25 AM b= Nov 10, 2009 10:21:25 AM I want to find difference between the a & b I googled and tried with some options but no luck. My OS is AIX (1 Reply)
Discussion started by: bandlan9
1 Replies

6. Shell Programming and Scripting

Difference between two timestamps Contd..

There was this thread earlier with the same name and the solution provided was excellent. Here is the solution to find diffrenc between two timestamp $ cat timestamp #! /usr/bin/ksh echo enter first time stamp read TIME1 echo enter second time stamp read TIME2 H1=${TIME1%:+()}... (3 Replies)
Discussion started by: Shellslave
3 Replies

7. Shell Programming and Scripting

finding difference between 2 directory recursively

Hi, i'm trying to compare two directories in Unix. I need a recursive search ie my shell script should also compare common files in those two directory and so on... any clues.. ?? (2 Replies)
Discussion started by: yayati
2 Replies

8. UNIX for Dummies Questions & Answers

how to find difference of 2 timestamps in secs?

I have a requirement to find the time difference in second between 2 given time stamps. An example scenario is shown below: 30 Oct 11:42:29:992 DEBUG org.apache.commons.digester.Digester - New match='form-validation/global/validator' (IID=, TID=) 30 Oct 11:42:29:993 DEBUG... (0 Replies)
Discussion started by: Alecs
0 Replies

9. Shell Programming and Scripting

Finding the time difference

Hi, I have two files A.txt and B.txt. And i have the following attributes in both the files. <date and time> <a unique id> For eg: <2007 May 30 20:29:36:034 GMT> <ID1> in A.txt <2007 May 30 20:42:36:038 GMT> <ID1> in B.txt Now, i need to find the time difference... (0 Replies)
Discussion started by: padma.raajesh
0 Replies

10. Solaris

Difference between two timestamps

I'm writting a script to find the difference between two timestamp. One field i get on delivery time of the file like 07:17 AM and other is my SLA time 06:30 AM I need to find the difference between these two time (time exceeded to meet SLA). Need some suggestions. (8 Replies)
Discussion started by: raman1605
8 Replies
Login or Register to Ask a Question