SUMMARY: Need time of last login for all users

From: Perttunen, Bruce <BPerttunen_at_bcbsm.com>
Date: Thu Jun 07 2001 - 14:21:52 EDT
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_000_01C0EF7E.B9ABB690
Content-Type: multipart/alternative;
	boundary="----_=_NextPart_001_01C0EF7E.B9ABB690"


------_=_NextPart_001_01C0EF7E.B9ABB690
Content-Type: text/plain;
	charset="iso-8859-1"

Here was my original question....

Does anyone know of an easy way to generate a list of all userids showing
the last time they logged - sorted by date?  I would rather not turn on
system accounting and don't want to create a script to format and sort the
date tag from the "last" command.  

I received quite a few replies which suggested everything from permutations
with the "last" command, perl scripts, and C programs.  Special thanks to
Mark Bolton who supplied me with a C program which, after a few small
modifications, did the trick.

Attached is a copy of program if anyone is interested.  I compiled this and
it gives me exactly what I want when I pipe it to "sort -n".

Bruce Perttunen
Unix Systems Administrator
Blue Cross Blue Shield of Michigan


------_=_NextPart_001_01C0EF7E.B9ABB690
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.2653.12">
<TITLE>SUMMARY: Need time of last login for all users</TITLE>
</HEAD>
<BODY>

<P><FONT SIZE=3D2>Here was my original question....</FONT>
</P>

<P><FONT SIZE=3D2>Does anyone know of an easy way to generate a list of =
all userids showing the last time they logged - sorted by date?&nbsp; I =
would rather not turn on system accounting and don't want to create a =
script to format and sort the date tag from the &quot;last&quot; =
command.&nbsp; </FONT></P>

<P><FONT SIZE=3D2>I received quite a few replies which suggested =
everything from permutations with the &quot;last&quot; command, perl =
scripts, and C programs.&nbsp; Special thanks to Mark Bolton who =
supplied me with a C program which, after a few small modifications, =
did the trick.</FONT></P>

<P><FONT SIZE=3D2>Attached is a copy of program if anyone is =
interested.&nbsp; I compiled this and it gives me exactly what I want =
when I pipe it to &quot;sort -n&quot;.</FONT></P>

<P><FONT SIZE=3D2>Bruce Perttunen</FONT>
<BR><FONT SIZE=3D2>Unix Systems Administrator</FONT>
<BR><FONT SIZE=3D2>Blue Cross Blue Shield of Michigan</FONT>
</P>

<P><FONT FACE=3D"Arial" SIZE=3D2 COLOR=3D"#000000"></FONT>&nbsp;

</BODY>
</HTML>
------_=_NextPart_001_01C0EF7E.B9ABB690--

------_=_NextPart_000_01C0EF7E.B9ABB690
Content-Type: application/octet-stream;
	name="lastlogin-webmaster.c"
Content-Disposition: attachment;
	filename="lastlogin-webmaster.c"

#include <stdio.h>
#include <fcntl.h>
#include <pwd.h>
#include <time.h>
main(){
        struct lastlog {
                long  ll_time;
                char  ll_line[8];
                char  ll_host[16];            /* same as in utmp */
        } l;
        int ll,i=0;
        struct tm TM,*localtime();
        void setpwent();
        struct passwd *pw,*getpwuid();
        char name[9];
        char gecos[40];

        printf ("%14-s   %8-s   %40-s\n", " Last Login", "Id", "Name");
        printf ("%14-s   %8-s   %40-s\n", "--------------", "--------", "------------------------------");

        ll = open ("/var/adm/lastlog",O_RDONLY);
        setpwent();

        while ( read(ll,&l,sizeof(l)) > 0 ) {
                if ( l.ll_time > 0 ) {
                        pw=getpwuid( i );
                           if ( pw == NULL )
                                strcpy (name,"???");
                           else
                                if ( pw->pw_uid > 9999 ) {
                                   strcpy (name,pw->pw_name);
                                   strcpy (gecos,pw->pw_gecos);
                                   TM = *localtime(&l.ll_time);
                                   printf ("%02d-%02d-%02d %02d:%02d   %8-s   %40-s\n",
                                   TM.tm_year%100,TM.tm_mon+1,TM.tm_mday,
                                   TM.tm_hour,TM.tm_min,
                                   name, gecos);
                                 }
                }
                i++;
        }
}

------_=_NextPart_000_01C0EF7E.B9ABB690--
Received on Thu Jun 7 19:21:52 2001

This archive was generated by hypermail 2.1.8 : Wed Mar 23 2016 - 16:24:56 EDT