Dear List,
I have a requirement for a maximum of one user logged in at any given time.  
Following is a .profile script I wrote to enforce the requirement.  The problem 
is that when the script runs, sometimes the user trying to login is identified 
as logged in and sometimes he/she is not identified as logged in.  I.e., there 
is a race condition between script execution and login completion.  Any advice 
for how to make it work properly?  The brute force way is to loop on waiting 
for the user to be logged in, as identified by the who command, and then check 
the time of the login so as not to be confused if the user is already logged 
in.  Is there a better way?  Thanks!
 
bash-2.04$ cat ./.profile

#!/usr/local/bin/bash
#
# Logout user if other user is logged in
#
shopt -s -o nounset
# Global Declarations
declare -rx SCRIPT=${0##*/}
declare USERS
#
# Logout User if Any Existing Users
$who
USERS=`$who | $wc -l`
printf "%s existing users on this machine\n" $USERS
if [ "$USERS" -gt "0" ] ; then
       printf "logging out\n"
       logout
fi
#
#  End of Script
#
_______________________________________________
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to "[EMAIL PROTECTED]"

Reply via email to