From mboxrd@z Thu Jan 1 00:00:00 1970 Message-ID: <96078617110189.tru64-unix-managers.marc@archive.invalid> From: Ellen Davis Date: Tue, 02 Sep 1997 13:43:18 +0000 To: tru64-unix-managers Subject: SUMMARY: number of logins X-MARC-Message: https://marc.info/?l=tru64-unix-managers&m=96078617110189 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