From owner-freebsd-questions@FreeBSD.ORG Wed Sep 14 19:07:23 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 2DF5A16A41F for ; Wed, 14 Sep 2005 19:07:23 +0000 (GMT) (envelope-from jbiddlew@yahoo.com) Received: from web52604.mail.yahoo.com (web52604.mail.yahoo.com [206.190.48.207]) by mx1.FreeBSD.org (Postfix) with SMTP id A911B43D4C for ; Wed, 14 Sep 2005 19:07:22 +0000 (GMT) (envelope-from jbiddlew@yahoo.com) Received: (qmail 67896 invoked by uid 60001); 14 Sep 2005 19:07:21 -0000 DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=s1024; d=yahoo.com; h=Message-ID:Received:Date:From:Subject:To:MIME-Version:Content-Type:Content-Transfer-Encoding; b=Cb5z1ZlnViFOj04WpxNECitKz2mqWMvGE6/VSI3IKLmD+2Cwt3m3tROpdm5EVgW9uBJN0fqWXNAmD5yqBnuIbVnSTkpGbxqz7Xvzc27A5HninbVl21gL/AUQqIj96c6gDwYjfipBTxtfbkZ+7GNlyBHBYCNFTWZCs2D8qBb3s/s= ; Message-ID: <20050914190721.67892.qmail@web52604.mail.yahoo.com> Received: from [68.197.182.5] by web52604.mail.yahoo.com via HTTP; Wed, 14 Sep 2005 12:07:20 PDT Date: Wed, 14 Sep 2005 12:07:20 -0700 (PDT) From: John Williams To: freebsd-questions@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit X-Content-Filtered-By: Mailman/MimeDel 2.1.5 Subject: script advice X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 14 Sep 2005 19:07:23 -0000 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 #