script advice

Noel Jones noeldude at gmail.com
Wed Sep 14 16:18:40 PDT 2005


On 9/14/05, John Williams <jbiddlew at yahoo.com> 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


More information about the freebsd-questions mailing list