From: Iwan R Tamimi <tamimii () m1 ! com ! sg>
To: tru64-unix-managers
Subject: SUMMARY: Info on file creation/modification up to the second
Date: Thu, 22 Feb 2001 09:49:15 +0000 [thread overview]
Message-ID: <98284170025363.tru64-unix-managers.marc@archive.invalid> (raw)
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: multipart/mixed; boundary="------_=_NextPart_001_01C09CB4.B7D9858A", Size: 24986 bytes --]
This message is in MIME format. Since your mail reader does not understand
this format, some or all of this message may not be legible.
------_=_NextPart_001_01C09CB4.B7D9858A
Content-Type: text/plain;
charset="iso-8859-1"
Hi All,
I thank you for the very quick answer to:
James Sainsbury and
J.A. Gutierrez
o James sugested to make c program using the stat() function. or using the
gnu ls which is part of fileutils which has this command:
% ls -l --full-time passwd
-rw-r--r-- 1 root root 858 Tue Jan 30 14:55:36 2001 passwd
o Mr. Gutierrez even give me the C source code to do it:
.c------------------------------------------------------------------
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <pwd.h>
#include <grp.h>
#include <time.h>
#include <errno.h>
main( int argc, char **argv)
{
struct stat sbp;
int f;
int isdevice=0;
struct passwd *pw;
struct group *gr;
char *name;
int error=0;
if ( argc == 1 )
{
fprintf(stderr,"Use: %s filename(s)\n",argv[0]);
exit(1);
}
for( f=1; f<argc; f ++)
{
printf("\n\tName:\t%s\n",argv[f]);
if ( stat(argv[f],&sbp)==-1)
{
perror("stat");
error++;
}
else
{
switch (sbp.st_mode & S_IFMT)
{
case S_IFIFO:
fprintf(stdout,"\t\tnamed pipe
(fifo)\n");
break;
case S_IFCHR:
fprintf(stdout,"\t\tcharacter
special\n");
isdevice=1;
break;
case S_IFDIR:
fprintf(stdout,"\t\tdirectory\n");
break;
case S_IFBLK:
fprintf(stdout,"\t\tblock
special\n");
isdevice=1;
break;
case S_IFREG:
fprintf(stdout,"\t\tregular\n");
break;
case S_IFLNK:
fprintf(stdout,"\t\tsymbolic
link\n");
break;
case S_IFSOCK:
fprintf(stdout,"\t\tsocket\n");
break;
default:
fprintf(stdout,"\t\tunknown\n");
break;
}
if (isdevice)
fprintf(stdout, "Device number:%d,%d\n",
(sbp.st_rdev>>8) & 0xff,
sbp.st_rdev & 0xff );
fprintf(stdout, "Resides on device:%d,%d\n",
(sbp.st_dev>>8) & 0xff,
sbp.st_dev & 0xff);
fprintf(stdout, "I-node: %d; Links: %d;
Size: %ld\n",
sbp.st_ino, sbp.st_nlink,
sbp.st_size);
if (( pw=getpwuid(sbp.st_uid))==NULL)
name="???";
else
name=pw->pw_name;
fprintf(stdout, "Owner ID: %d; Name: %s\n",
sbp.st_uid, name);
if (( gr=getgrgid(sbp.st_gid))==NULL)
name="???";
else
name=gr->gr_name;
fprintf(stdout, "Group ID: %d; Name: %s\n",
sbp.st_gid, name);
if ((sbp.st_mode & S_ISUID )== S_ISUID )
fprintf(stdout, "Set-user-ID\n");
if ((sbp.st_mode & S_ISGID )== S_ISGID )
fprintf(stdout, "Set-group-ID\n");
if ((sbp.st_mode & S_ISVTX )== S_ISVTX )
fprintf(stdout, "Save swapped text
after use\n");
fprintf(stdout, "Permissions:
%o\n",sbp.st_mode & 0xfff);
fprintf(stdout, "Last access: %s",
asctime(localtime(&sbp.st_atime )));
fprintf(stdout, "Last modification: %s",
asctime(localtime(&sbp.st_mtime )));
fprintf(stdout, "Last status change: %s",
asctime(localtime(&sbp.st_ctime )));
}
}
exit(error);
}
---------------------------------------------------------------------------
Thank you all for the very quick response and the informations.
Best Regards,
Iwan
------_=_NextPart_001_01C09CB4.B7D9858A
Content-Type: text/html;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV=3D"Content-Type" CONTENT=3D"text/html; =
charset=3Diso-8859-1">
<META NAME=3D"Generator" CONTENT=3D"MS Exchange Server version =
5.5.2448.0">
<TITLE>SUMMARY: Info on file creation/modification up to the =
second</TITLE>
</HEAD>
<BODY>
<P><FONT SIZE=3D2>Hi All,</FONT>
</P>
<P><FONT SIZE=3D2>I thank you for the very quick answer to:</FONT>
<BR><FONT SIZE=3D2>James Sainsbury and</FONT>
<BR><FONT SIZE=3D2>J.A. Gutierrez</FONT>
</P>
<P><FONT SIZE=3D2>o James sugested to make c program using the =
stat() function. or using the gnu ls which is part of fileutils which =
has this command:</FONT></P>
<P><FONT SIZE=3D2>% ls -l --full-time passwd</FONT>
<BR><FONT SIZE=3D2>-rw-r--r-- 1 =
root =
root 858 Tue Jan =
30 14:55:36 2001 passwd</FONT>
</P>
<P><FONT SIZE=3D2>o Mr. Gutierrez even give me the C source code to do =
it:</FONT>
</P>
<P><FONT =
SIZE=3D2>.c-------------------------------------------------------------=
-----</FONT>
<BR><FONT SIZE=3D2>#include <stdio.h></FONT>
<BR><FONT SIZE=3D2>#include <sys/types.h></FONT>
<BR><FONT SIZE=3D2>#include <sys/stat.h></FONT>
<BR><FONT SIZE=3D2>#include <pwd.h></FONT>
<BR><FONT SIZE=3D2>#include <grp.h></FONT>
<BR><FONT SIZE=3D2>#include <time.h></FONT>
<BR><FONT SIZE=3D2>#include <errno.h></FONT>
</P>
<BR>
<P><FONT SIZE=3D2>main( int argc, char **argv)</FONT>
<BR><FONT SIZE=3D2>{</FONT>
<BR> <FONT SIZE=3D2>struct =
stat sbp;</FONT>
<BR> <FONT =
SIZE=3D2>int =
=
f;</FONT>
<BR> <FONT =
SIZE=3D2>int =
=
isdevice=3D0;</FONT>
<BR> <FONT SIZE=3D2>struct =
passwd *pw;</FONT>
<BR> <FONT SIZE=3D2>struct =
group *gr;</FONT>
<BR> <FONT =
SIZE=3D2>char =
=
*name;</FONT>
<BR> <FONT =
SIZE=3D2>int =
=
=
error=3D0;</FONT>
</P>
<P> <FONT SIZE=3D2>if ( argc =
=3D=3D 1 )</FONT>
<BR> <FONT SIZE=3D2>{</FONT>
<BR> =
<FONT =
SIZE=3D2>fprintf(stderr,"Use: %s =
filename(s)\n",argv[0]);</FONT>
<BR> =
<FONT =
SIZE=3D2>exit(1);</FONT>
<BR> <FONT SIZE=3D2>}</FONT>
<BR> <FONT SIZE=3D2>for( =
f=3D1; f<argc; f ++)</FONT>
<BR> <FONT SIZE=3D2>{</FONT>
<BR> =
<FONT =
SIZE=3D2>printf("\n\tName:\t%s\n",argv[f]);</FONT>
</P>
<P> =
<FONT SIZE=3D2>if ( =
stat(argv[f],&sbp)=3D=3D-1)</FONT>
<BR> =
<FONT SIZE=3D2>{</FONT>
<BR> =
=
<FONT =
SIZE=3D2>perror("stat");</FONT>
<BR> =
=
<FONT =
SIZE=3D2>error++;</FONT>
<BR> =
<FONT SIZE=3D2>}</FONT>
<BR> =
<FONT SIZE=3D2>else</FONT>
<BR> =
<FONT SIZE=3D2>{</FONT>
<BR> =
=
<FONT SIZE=3D2>switch =
(sbp.st_mode & S_IFMT)</FONT>
<BR> =
=
<FONT SIZE=3D2>{</FONT>
<BR> =
=
=
<FONT SIZE=3D2>case =
S_IFIFO:</FONT>
<BR> =
=
=
=
<FONT =
SIZE=3D2>fprintf(stdout,"\t\tnamed pipe (fifo)\n");</FONT>
<BR> =
=
=
=
<FONT SIZE=3D2>break;</FONT>
<BR> =
=
=
<FONT SIZE=3D2>case =
S_IFCHR:</FONT>
<BR> =
=
=
=
<FONT =
SIZE=3D2>fprintf(stdout,"\t\tcharacter special\n");</FONT>
<BR> =
=
=
=
<FONT =
SIZE=3D2>isdevice=3D1;</FONT>
<BR> =
=
=
=
<FONT SIZE=3D2>break;</FONT>
<BR> =
=
=
<FONT SIZE=3D2>case =
S_IFDIR:</FONT>
<BR> =
=
=
=
<FONT =
SIZE=3D2>fprintf(stdout,"\t\tdirectory\n");</FONT>
<BR> =
=
=
=
<FONT SIZE=3D2>break;</FONT>
<BR> =
=
=
<FONT SIZE=3D2>case =
S_IFBLK:</FONT>
<BR> =
=
=
=
<FONT =
SIZE=3D2>fprintf(stdout,"\t\tblock special\n");</FONT>
<BR> =
 =
; =
<FONT =
SIZE=3D2>isdevice=3D1;</FONT>
<BR> =
=
=
=
<FONT SIZE=3D2>break;</FONT>
<BR> =
=
=
<FONT SIZE=3D2>case =
S_IFREG:</FONT>
<BR> =
=
=
=
<FONT =
SIZE=3D2>fprintf(stdout,"\t\tregular\n");</FONT>
<BR> =
=
=
=
<FONT SIZE=3D2>break;</FONT>
<BR> =
=
=
<FONT SIZE=3D2>case =
S_IFLNK:</FONT>
<BR> =
=
=
=
<FONT =
SIZE=3D2>fprintf(stdout,"\t\tsymbolic link\n");</FONT>
<BR> =
=
=
=
<FONT SIZE=3D2>break;</FONT>
<BR> =
=
=
<FONT SIZE=3D2>case =
S_IFSOCK:</FONT>
<BR> =
=
=
=
<FONT =
SIZE=3D2>fprintf(stdout,"\t\tsocket\n");</FONT>
<BR> =
=
=
=
<FONT SIZE=3D2>break;</FONT>
<BR> =
=
=
<FONT =
SIZE=3D2>default:</FONT>
<BR> =
=
=
=
<FONT =
SIZE=3D2>fprintf(stdout,"\t\tunknown\n");</FONT>
<BR> =
=
=
=
<FONT SIZE=3D2>break;</FONT>
<BR> =
=
<FONT SIZE=3D2>}</FONT>
<BR> =
=20
<BR> =
=
<FONT SIZE=3D2>if =
(isdevice)</FONT>
<BR> =
=
=
<FONT =
SIZE=3D2>fprintf(stdout, "Device number:%d,%d\n",</FONT>
<BR> =
=
=
=
=
<FONT =
SIZE=3D2>(sbp.st_rdev>>8) & 0xff,</FONT>
<BR> =
=
=
=
=
<FONT SIZE=3D2>sbp.st_rdev =
& 0xff );</FONT>
</P>
<P> =
=
=
<FONT =
SIZE=3D2>fprintf(stdout, "Resides on device:%d,%d\n",</FONT>
<BR> =
=
=
=
=
<FONT =
SIZE=3D2>(sbp.st_dev>>8) & 0xff,</FONT>
<BR> =
=
=
=
=
<FONT SIZE=3D2>sbp.st_dev =
& 0xff);</FONT>
<BR> =
=20
<BR> =
=
=
<FONT =
SIZE=3D2>fprintf(stdout, "I-node: %d; Links: %d; Size: =
%ld\n",</FONT>
<BR> =
=
=
=
=
<FONT SIZE=3D2>sbp.st_ino, =
sbp.st_nlink, sbp.st_size);</FONT>
</P>
<P> =
=
=
<FONT SIZE=3D2>if (( =
pw=3Dgetpwuid(sbp.st_uid))=3D=3DNULL)</FONT>
<BR> =
=
=
=
<FONT =
SIZE=3D2>name=3D"???";</FONT>
<BR> =
=
=
<FONT SIZE=3D2>else</FONT>
<BR> =
=
=
=
<FONT =
SIZE=3D2>name=3Dpw->pw_name;</FONT>
</P>
<P> =
=
=
<FONT =
SIZE=3D2>fprintf(stdout, "Owner ID: %d; Name: %s\n", =
sbp.st_uid, name);</FONT>
</P>
<BR>
<P> =
=
=
<FONT SIZE=3D2>if (( =
gr=3Dgetgrgid(sbp.st_gid))=3D=3DNULL)</FONT>
<BR> =
=
=
=
<FONT =
SIZE=3D2>name=3D"???";</FONT>
<BR> =
=
 =
; <FONT SIZE=3D2>else</FONT>
<BR> =
=
=
=
<FONT =
SIZE=3D2>name=3Dgr->gr_name;</FONT>
</P>
<P> =
=
=
<FONT =
SIZE=3D2>fprintf(stdout, "Group ID: %d; Name: %s\n", =
sbp.st_gid, name);</FONT>
</P>
<P> =
=
=
<FONT SIZE=3D2>if =
((sbp.st_mode & S_ISUID )=3D=3D S_ISUID )</FONT>
<BR> =
=
=
=
<FONT =
SIZE=3D2>fprintf(stdout, "Set-user-ID\n");</FONT>
</P>
<P> =
=
=
<FONT SIZE=3D2>if =
((sbp.st_mode & S_ISGID )=3D=3D S_ISGID )</FONT>
<BR> =
=
=
=
<FONT =
SIZE=3D2>fprintf(stdout, "Set-group-ID\n");</FONT>
</P>
<P> =
=
=
<FONT SIZE=3D2>if =
((sbp.st_mode & S_ISVTX )=3D=3D S_ISVTX )</FONT>
<BR> =
=
=
=
<FONT =
SIZE=3D2>fprintf(stdout, "Save swapped text after =
use\n");</FONT>
</P>
<P> =
=
=
<FONT =
SIZE=3D2>fprintf(stdout, "Permissions: %o\n",sbp.st_mode =
& 0xfff);</FONT>
<BR> =
=
=
<FONT =
SIZE=3D2>fprintf(stdout, "Last =
access: =
%s",</FONT>
<BR> =
=
=
=
<FONT =
SIZE=3D2>asctime(localtime(&sbp.st_atime )));</FONT>
<BR> =
=
=
<FONT =
SIZE=3D2>fprintf(stdout, "Last modification: =
%s",</FONT>
<BR> =
=
=
=
<FONT =
SIZE=3D2>asctime(localtime(&sbp.st_mtime )));</FONT>
<BR> =
=
=
<FONT =
SIZE=3D2>fprintf(stdout, "Last status change: =
%s",</FONT>
<BR> =
=
=
 =
; <FONT SIZE=3D2>asctime(localtime(&sbp.st_ctime =
)));</FONT>
</P>
<P> =
<FONT SIZE=3D2>}</FONT>
<BR> <FONT SIZE=3D2>}</FONT>
<BR> <FONT =
SIZE=3D2>exit(error);</FONT>
<BR><FONT SIZE=3D2>}</FONT>
</P>
<P><FONT =
SIZE=3D2>---------------------------------------------------------------=
------------</FONT>
</P>
<P><FONT SIZE=3D2>Thank you all for the very quick response and the =
informations.</FONT>
</P>
<P><FONT SIZE=3D2>Best Regards,</FONT>
</P>
<P><FONT SIZE=3D2>Iwan</FONT>
</P>
</BODY>
</HTML>
------_=_NextPart_001_01C09CB4.B7D9858A--
reply other threads:[~2001-02-22 9:49 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
read-only archive
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox