From: Ellen Davis <daviser () email ! uc ! edu>
To: tru64-unix-managers
Subject: SUMMARY: number of logins
Date: Tue, 02 Sep 1997 13:43:18 +0000 [thread overview]
Message-ID: <96078617110189.tru64-unix-managers.marc@archive.invalid> (raw)
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
reply other threads:[~1997-09-02 13:43 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