Date: Wed, 14 Sep 2005 16:36:54 -0500 From: Noel Jones <noeldude@gmail.com> To: freebsd-questions@freebsd.org Subject: Re: script advice Message-ID: <cce506b0509141436633a36c0@mail.gmail.com> In-Reply-To: <20050914190721.67892.qmail@web52604.mail.yahoo.com> References: <20050914190721.67892.qmail@web52604.mail.yahoo.com>
next in thread | previous in thread | raw e-mail | index | archive | help
On 9/14/05, John Williams <jbiddlew@yahoo.com> wrote: > Dear List, > I have a requirement for a maximum of one user logged in at any given tim= e. 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 i= s 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 com= pletion. 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 w= ho command, and then check the time of the login so as not to be confused i= f the user is already logged in. Is there a better way? Thanks! >=20 Exclude the users own tty. TTYDEV=3D`/usr/bin/tty` TTY=3D`/usr/bin/basename $TTYDEV` USERS=3D`/usr/bin/who | /usr/bin/grep -v "$TTY"` [ -z "$USERS" ] && { echo Other users logged on! echo $USERS echo logging out... logout } --=20 Noel Jones
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?cce506b0509141436633a36c0>