script advice

2005-09-14 Thread John Williams
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]


Re: script advice

2005-09-14 Thread Noel Jones
On 9/14/05, John Williams [EMAIL PROTECTED] wrote:
 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!
 

Exclude the users own tty.

TTYDEV=`/usr/bin/tty`
TTY=`/usr/bin/basename $TTYDEV`
USERS=`/usr/bin/who | /usr/bin/grep -v $TTY`

[ -z $USERS ]   {
   echo Other users logged on!
   echo $USERS
   echo logging out...
   logout
}


-- 
Noel Jones
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to [EMAIL PROTECTED]