tru64-unix-managers (formerly alpha-osf-managers) (1994-2012)
 help / color / mirror / Atom feed
* SUMMARY: number of logins
@ 1997-09-02 13:43 Ellen Davis
  0 siblings, 0 replies; only message in thread
From: Ellen Davis @ 1997-09-02 13:43 UTC (permalink / raw)
  To: tru64-unix-managers


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@uc.edu

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~1997-09-02 13:43 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
1997-09-02 13:43 SUMMARY: number of logins Ellen Davis

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox