From owner-freebsd-questions@FreeBSD.ORG Wed Sep 14 23:18:40 2005 Return-Path: X-Original-To: freebsd-questions@freebsd.org Delivered-To: freebsd-questions@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 69C2116A41F for ; Wed, 14 Sep 2005 23:18:40 +0000 (GMT) (envelope-from noeldude@gmail.com) Received: from zproxy.gmail.com (zproxy.gmail.com [64.233.162.200]) by mx1.FreeBSD.org (Postfix) with ESMTP id 8CD7743D46 for ; Wed, 14 Sep 2005 23:18:39 +0000 (GMT) (envelope-from noeldude@gmail.com) Received: by zproxy.gmail.com with SMTP id o1so14359nzf for ; Wed, 14 Sep 2005 16:18:38 -0700 (PDT) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:reply-to:to:subject:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=WEneSUlJBQYXVsyVNrU2Qc5GCYgk+Gqro/T7kh7zFjKFfvpGz9dIFuippbhYrm80CIImF8xwX9pjBQXkoAoNlJ/4dw1nq9RV4RE3c1+zW74w6A/Mq1UtOSAZr3FAkI02/fWNughewVhz2ClkH92ZmB1yj/UUcvcXOxQivFGSZrw= Received: by 10.54.40.64 with SMTP id n64mr1229753wrn; Wed, 14 Sep 2005 14:36:54 -0700 (PDT) Received: by 10.54.84.1 with HTTP; Wed, 14 Sep 2005 14:36:54 -0700 (PDT) Message-ID: Date: Wed, 14 Sep 2005 16:36:54 -0500 From: Noel Jones To: freebsd-questions@freebsd.org In-Reply-To: <20050914190721.67892.qmail@web52604.mail.yahoo.com> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline References: <20050914190721.67892.qmail@web52604.mail.yahoo.com> Subject: Re: script advice X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: noeldude@gmail.com List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 14 Sep 2005 23:18:40 -0000 On 9/14/05, John Williams 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