UNIX Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
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 February 13th, 2004, 02:42 AM
kaushik2004 kaushik2004 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2004
Location: san jose
Posts: 2 kaushik2004 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Finding the elapsed time

Hi,

I would like to find the elapsed time(in hours and minutes) since a certain file was modified by comparing it with the system time.

Is there an unix command that can give me this value easily?There is a command called 'tract' which can give this value easily but unfortunately Solaris and HP-UX versions am using do not have this.

Please advise me if there is a simple way of doing this.

Thanks in Advance,
Kaushik

Reply With Quote
  #2  
Old February 14th, 2004, 04:11 PM
fpmurphy fpmurphy is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2003
Location: USA
Posts: 331 fpmurphy User rank is Private First Class (20 - 50 Reputation Level)fpmurphy User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 1 Day 11 h 55 m 2 sec
Reputation Power: 7
Source code for tract is available here:

http://aips2.nrao.edu/docs/programmer/source.html

and elsewhere.

- F

Reply With Quote
  #3  
Old February 15th, 2004, 02:36 AM
kaushik2004 kaushik2004 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2004
Location: san jose
Posts: 2 kaushik2004 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Hi,
There is a way to get this via Perl using time and stat functions.

The 'time' function gives the Time in seconds since 1970. While the stat function can give the modified time in seconds. The difference will be the elapsed time.

Now, do we have a similar function like 'time' in unix ? Has anyone used 'stat' function before in Unix ?

Thanks,
Kaushik

Reply With Quote
  #4  
Old February 15th, 2004, 09:48 AM
fpmurphy fpmurphy is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2003
Location: USA
Posts: 331 fpmurphy User rank is Private First Class (20 - 50 Reputation Level)fpmurphy User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 1 Day 11 h 55 m 2 sec
Reputation Power: 7
OK, here is a quick C code example of how to get
what you want.

#include <stdio.h>
#include <time.h>
#include <sys/types.h>
#include <sys/stat.h>

int
main(int argc, char **argv)
{
struct stat sbuf;
time_t t1, t2;

if (argc < 2) {
fprintf(stderr, "Usage: %s file\n", argv[0]);
exit(1);
}

(void) time(&t1);

if (stat(argv[1], &sbuf) < 0) {
fprintf(stderr, "ERROR: stat failed\n");
exit(1);
}

fprintf(stdout, "\nSystem time: %s", ctime(&t1));
fprintf(stdout, "File last modified at: %s",
ctime(&sbuf.st_mtime));

fprintf(stdout, "Elapsed time: %ld secs\n",
(long) &sbuf.st_mtime - ((long)&t1));

}

Reply With Quote
  #5  
Old May 4th, 2004, 02:32 AM
NPRao NPRao is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2004
Location: Pacific NW, USA
Posts: 26 NPRao User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 9 h 51 m 42 sec
Reputation Power: 0
Send a message via AIM to NPRao
Look up man ll there are options (u, l, c) to see the last modified, accessed, etc times.

Reply With Quote
  #6  
Old May 4th, 2004, 10:31 AM
cuppjr cuppjr is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2004
Posts: 2 cuppjr User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Unhappy Rf FPMURPHY's c program

[root@servername root]# ./a.out discoverer.key

System time: Tue May 4 10:30:07 2004
File last modified at: Tue Feb 24 13:30:59 2004
Elapsed time: 68 secs


Doesn't work that well, I believe -

Reply With Quote
Reply

Viewing: Dev Shed ForumsOperating SystemsUNIX Help > Finding the elapsed time


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




 Free IT White Papers!
 
How to Present Effectively Online
This white paper offers practical and actionable advice on the key steps that any presenter should consider as they plan and execute a Webinar or online meeting.

 
Open Source Security Myths
Open Source Software (OSS) is computer software whose source code is available to the general public with relaxed or non-existent intellectual property restrictions (or arrangement such as the public domain), and is usually developed with the input of many contributors.

 
Power and Cooling Capacity Management for Data Centers
This paper describes the principles for achieving power and cooling capacity management.

 
Scalable, Fault-Tolerant NAS for Oracle - The Next Generation
For several years NAS has been evolving as a storage alternative for Oracle databases, and for good reason: NAS is quite often the simplest, most cost-effective storage approach for Oracle. Learn about the benefits that HP's approach to scalable NAS brings to Oracle environments in this comprehensive white paper.

 
Understanding Web Application Security Challenges
This white paper discusses many common threats and preventive measures for Web application security, and explains what you can do to help protect your organization.

 

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




© 2003-2010 by Developer Shed. All rights reserved. DS Cluster 8 Hosted by Hostway
For more Enterprise Application Development news, visit eWeek