- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- c script to get inode time_t info from file on hpu...
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-26-2007 01:58 AM
тАО03-26-2007 01:58 AM
of a file in a directory.
I can query the timestamp with ls -ls,
but I want to to use a variable to store
it in, and I see there is an inbuilt function available for this on hpux called inode().
see man inode.
So, It must be possible to use a smal c prog
to do that , only I have limited c experience and I do not know how I can make sure I retrieve the inode value of :
time_t di_mtime; /* time last modified */ from the file I want.
If anyone had some work done in this directory and help me in the right direction.
Cheers.
Solved! Go to Solution.
- Tags:
- stat
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-26-2007 02:03 AM
тАО03-26-2007 02:03 AM
SolutionThe system call that you are looking for is called 'stat(2)'. You can easily use this in Perl:
# perl -le '$t=(stat($ARGV[0]))[9];print "$t\n",scalar localtime($t)' file
...will print the 'mtime' in epoch seconda and a second line expressed in your localtime for the filename passed as an argument.
Regards!
...JRF...
- Tags:
- Perl
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-26-2007 02:06 AM
тАО03-26-2007 02:06 AM
Re: c script to get inode time_t info from file on hpux
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-26-2007 02:29 AM
тАО03-26-2007 02:29 AM
Re: c script to get inode time_t info from file on hpux
Frank if you really still want a C program,
see Josephs answer here:
http://forums1.itrc.hp.com/service/forums/questionanswer.do?threadId=25592
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-26-2007 03:05 AM
тАО03-26-2007 03:05 AM
Re: c script to get inode time_t info from file on hpux
------------------------------------------
#include
#include
#include
#include
#include
#include
#define FALSE (0)
#define TRUE (1)
#define assign_errno(x) ((errno != 0) ? errno : (x))
static void problem(const char *s, int err)
{
(void) fprintf(stderr,"%s (%d)\n",s,err);
(void) fflush(stderr);
return;
} /* problem */
static int format_time(time_t s)
{
int cc = 0;
struct tm *t;
static int done = FALSE;
if (!done)
{
tzset();
done = TRUE;
}
t = localtime(&s);
if (t != NULL)
{
(void) printf("%4d%02d%2d %02d:%02d:%02d",(int) (t->tm_year + 1900),
(int) (t->tm_mon + 1), (int)t->tm_mday,
(int) t->tm_hour, (int) t->tm_min, (int) t->tm_sec);
if ((t->tm_isdst >= 0) && (t->tm_isdst <= 1))
{
(void) printf(" %s",tzname[t->tm_isdst]);
}
}
else cc = assign_errno(250);
return(cc);
} /* format_time */
int main(int argc, char *argv[])
{
int cc = 0;
if (argc > 1)
{
struct stat s;
cc = stat(argv[1],&s);
if (cc == 0)
{
(void) printf("%ld ",(unsigned long) s.st_mtime);
(void) format_time(s.st_mtime);
(void) printf("\n");
}
else
{
cc = assign_errno(254);
(void) fprintf(stderr,"Can't stat '%s'\n",argv[1]);
problem("Stat failed",cc);
}
}
else
{
cc = 255;
problem("Missing argument",cc);
}
return(cc);
} /* main */
--------------------------------------------
Oh, and to be nit-picky as it pertains to one of the responses you got, there is no creation time associated with a file. UNIX has no notion of creation time. The tm_ctime in struct tm refers not to creation time but rather change time which is one of UNIX's more confusing concepts is different from modification time. ctime refers to when metadata changes (owner, group, mode, length) and mtime refers to actual changes to the data itself. For example, an update (write) of an existing block of a file would alter mtime but leave ctime intact. However,
a write() at the end of file (ie an append) would modify both mtime and ctime because the length of the file changed and thus the metadata requires an update.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-26-2007 03:17 AM
тАО03-26-2007 03:17 AM
Re: c script to get inode time_t info from file on hpux
...and while we are on the subject of timestamps, the Perl solution I showed can easily be modified to sample either the 'atime' (last access time) or the 'ctime' (last inode change time). The 'stat()' structure given to Perl consists of thirteen elements. The timestamps are respectively:
atime => 8
mtime => 9
ctime => 10
Hence if you wanted the 'atime' of a file, do:
# perl -le '$t=(stat($ARGV[0]))[8];print "$t\n",scalar localtime($t)' file
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-26-2007 03:17 AM
тАО03-26-2007 03:17 AM
Re: c script to get inode time_t info from file on hpux
In sharing your wizardry and for
sticking up for me :).
In the meantime I followed Peter's link
to a fair bit of ingredients.
I did a wee bit of cooking and came up
with what I wanted.
However I will review your stuff in order
to improve my first version.
Thanks to all
/* get original inode stats of file */
#include
#include
#include
#include
main() {
struct stat info;
struct tm *tm;
struct tf *tf;
char s[32];
if (stat("getu", &info) != 0)
perror("stat() error");
else {
tm = localtime(&info.st_mtime);
strftime(s, sizeof(s), "%d/%m/%Y %H:%M%S", tm);
/*strftime(buf, sizeof(buf), "%d/%m/%Y", tm); */
puts("stat() returned the following information:");
printf(" time_t: %d\n", info.st_mtime); /* Last modification time */
printf(" time: %d\n", tm); /* Last modification time */
printf(" time_f: %s\n", s);
printf(" inode: %d\n", (int) info.st_ino);
printf(" dev id: %d\n", (int) info.st_dev);
printf(" mode: %08x\n", info.st_mode);
printf(" links: %d\n", info.st_nlink);
printf(" uid: %d\n", (int) info.st_uid);
printf(" gid: %d\n", (int) info.st_gid);
exit(0);
}
}
Fr..
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-26-2007 07:32 PM
тАО03-26-2007 07:32 PM