SUMMARY: number of logins

From: Ellen Davis <daviser_at_email.uc.edu>
Date: Tue, 02 Sep 1997 09:43:18 -0400

Original question:
I use a C program for everyone's default shell. I wanted to find the
number of concurrent logins for a user from a C program.

Thanks to:
Richard Eisenman
Stephen Carpenter
 Joe Wilson
George Gallen
Alex_Nord
Randy M. Hayman
John K. Peterson
Robert L. McMillin
Santosh Krishna
Kurt Carlson
Yasir

Some responses suggested calling a script using the system call such as the
example below provided by Alex Nord.
     myname=whoami
     count=`who -u | grep $myname | wc -l`
     exit $count

Most responses indicated that I needed to read the utmp file. John
Peterson wrote that there is a system call, getutent, which does just that.
 I ended up using the getutent call. Here is the code. Comments on the
code are welcome!

setutent();
u = getutent();
while (u != NULL) {
   if (strncmp(passptr->pw_name,u->ut_name,strlen(passptr->pw_name)) == 0)
        usercount = usercount +1;
   u = getutent();
   }
endutent();
if (usercount > limit) {
   printf("Number of maximum concurrent logins reached.\n");
   printf("You need to logoff your current session before you can login
again.\n
");
   sleep(5);
   exit(1);
   }




 Ellen Davis
 Ellen.Davis_at_uc.edu
Received on Tue Sep 02 1997 - 15:56:05 NZST

This archive was generated by hypermail 2.4.0 : Wed Nov 08 2023 - 11:53:36 NZDT