UNIX Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsOperating SystemsUNIX Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old March 13th, 2012, 09:37 PM
peckenson peckenson is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2012
Posts: 3 peckenson User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 37 m 24 sec
Reputation Power: 0
How to find diff in time stamp

ls -lrt /usr/local/intranet/areas/prod/output/SRGW_0?/
O/P of above command.
drwxr-xr-x 2 mtsadm mts 4096 Mar 13 10:44 153913
drwxr-xr-x 2 mtsadm mts 4096 Mar 13 10:48 153914
drwxr-xr-x 2 mtsadm mts 4096 Mar 13 10:53 153915
drwxr-xr-x 2 mtsadm mts 4096 Mar 13 10:57 153916
drwxr-xr-x 2 mtsadm mts 4096 Mar 13 11:01 153917
drwxr-xr-x 2 mtsadm mts 4096 Mar 13 11:05 153918
drwxr-xr-x 2 mtsadm mts 4096 Mar 13 11:10 153919
drwxr-xr-x 2 mtsadm mts 4096 Mar 13 11:14 153921
drwxr-xr-x 2 mtsadm mts 4096 Mar 13 11:14 153920
Load time of 153913 = 4 minutes.
I need to in corporate a logic similar to this but need to do it in a loop as there are many directories for load time calculation.
Store in a variable = ls -lrt /usr/local/intranet/areas/prod/output/SRGW_05/ | cut -f24 -d" "
h1=`echo $T1|cut -d: -f1`
m1=`echo $T1|cut -d: -f2`
x1=`echo "$h1*60 + $m1"|bc -l`
h2=`echo $T2|cut -d: -f1`
m2=`echo $T2|cut -d: -f2`
x2=`echo "$h2*60 + $m2"|bc -l`
if test $x1 -lt $x2
then
diff=`echo "$x2 - $x1"|bc -l`
else
diff=`echo "$x1 - $x2"|bc -l`
fi
echo "Load time is $diff"


Can some one give me the answer

Reply With Quote
  #2  
Old March 14th, 2012, 12:13 PM
SimonJM SimonJM is offline
Contributing User
Dev Shed Regular (2000 - 2499 posts)
 
Join Date: Mar 2006
Posts: 2,108 SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level) 
Time spent in forums: 1 Month 1 Week 1 Day 4 h 16 m 23 sec
Reputation Power: 1485
Ok, now we have an idea of what you are after (having had it clarified in another thread):

I suspect throwing some form of the basic data (the directory listing) at awk will be the way to go for this. Things may go 'creaky' if a time period spans midnight, so be warned! Also, there seems to be no way of determining the time difference for the earliest entry - you'll have the end time, but no start time. I'll be rash and assume that it will be available at run time, and you can pass it to the command.

We, for this, really only care about the directory name and the time stamp, so we can drop the user and group names from the output:
Code:
ls -logtr /usr/local/intranet/areas/prod/output/SRGW_0?/

will produce a basic-ish list which we can use awk to 'chomp' at:

Code:
ls -logtr | awk -vSTART="hh:mm" 
  ' function tdiff(d, s, e) {
      split(s,t1,":"); split(e,t2,":");
      t1m=t1[1]*60+t1[2]; t2m=t2[1]*60+t2[2];
      td=t1m-t2m;
      print d, td;
    }
  BEGIN { x=0; n=""; ts=""; te="" }
  {
     if (NR==1} {
        n=$6; te=$5;
     }
     else {
       ts=$5; tdiff(n, ts, te); n=$6; te=ts; ts=$5;
     }
   }
   END { tdiff(n, START, te) }
   '

The above should (if the brackets all match up!) do pretty much what you need.
We take the ls output, pipe it into awk. You will need to supple the correct value for the -vSTART="hh:mm", replacing the hh:mm with the correct time.
We set some defaults inthe BEGIN clause, then in the main code we check to see if this is the first time through - by using the internal NR variable which will be 1 or the first row of the input. If it is we remember the directory name and the time.
Next, and subsequent times round the loop we will have two sets of data - from the previous row and from the current row.
It is then just a matter of juggling the data, getting the difference in times (using a function as we will be doing the same thing in two places), and printing that out. After that we rotate the current row data into the old row variables and get ready to do it again.
To process the final row we need the input from our 'dummy' START variable to provide what we would have used by getting the next row, and call out function again.
__________________
The moon on the one hand, the dawn on the other:
The moon is my sister, the dawn is my brother.
The moon on my left and the dawn on my right.
My brother, good morning: my sister, good night.
-- Hilaire Belloc

Reply With Quote
  #3  
Old March 14th, 2012, 01:20 PM
b49P23TIvg's Avatar
b49P23TIvg b49P23TIvg is offline
Contributing User
Dev Shed Loyal (3000 - 3499 posts)
 
Join Date: Aug 2011
Posts: 3,357 b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 1 Month 2 Weeks 3 Days 9 h 6 m 43 sec
Reputation Power: 383
Great.

Now for the recursive/many directories part:

/local/intranet/areas/prod/output/ -type d -exec script.sh {} \;


script.sh holds (or whichever ls options work with your awk program)

path=$1
echo IN DIRECTORY "$path"
ls --sort=time --full-time $path | gawk -f diff_in_time_stamp.awk
__________________
[code]Code tags[/code] are essential for python code!

Reply With Quote
Reply

Viewing: Dev Shed ForumsOperating SystemsUNIX Help > How to find diff in time stamp

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap