From owner-freebsd-isp@FreeBSD.ORG Mon Apr 26 03:49:44 2004 Return-Path: Delivered-To: freebsd-isp@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 9480616A4CE for ; Mon, 26 Apr 2004 03:49:44 -0700 (PDT) Received: from ns2.wananchi.com (ns2.wananchi.com [62.8.64.4]) by mx1.FreeBSD.org (Postfix) with ESMTP id E254C43D6A for ; Mon, 26 Apr 2004 03:49:42 -0700 (PDT) (envelope-from wash@wananchi.com) Received: from wash by ns2.wananchi.com with local (Exim 4.32 #0 (FreeBSD 4.9)) id 1BI3g9-000GxD-H2 by authid for ; Mon, 26 Apr 2004 13:49:37 +0300 Date: Mon, 26 Apr 2004 13:49:37 +0300 From: Odhiambo Washington To: freebsd-isp@freebsd.org Message-ID: <20040426104937.GA58605@ns2.wananchi.com> Mail-Followup-To: Odhiambo Washington , freebsd-isp@freebsd.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline X-Disclaimer: Any views expressed in this message,where not explicitly attributed otherwise, are mine alone!. X-Mailer: Mutt 1.5.5.1i (2003-11-05) X-Designation: Systems Administrator, Wananchi Online Ltd. X-Location: Nairobi, KE, East Africa. User-Agent: Mutt/1.5.5.1i Subject: pw and file locking X-BeenThere: freebsd-isp@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Internet Services Providers List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 26 Apr 2004 10:49:44 -0000 Hi, I am using pw to process users on my box from a small script. What happens is that one script on a different machines executes the script (below) on another machine with the required variables. NB: It is quite possible that the script on the remote box can be executed by two processes simultaneously, so my concern here would be about locking. Variously I have ended up with a corrupted master.passwd file and I had to restore from backup (Thanks to FreeBSD periodic-daily scripts). Here is the script, very simplistic, but it works: #!/bin/sh # -- useradd # Script to ADD a mail account # This script essentially requires the following data: # username = $1 # realname = $2 # password = $3 # PW=`which pw` OPERATION='useradd' # Note: I am not quite sure about how to handle the initial password entry.. # So I am doing that on the 2nd step .. # Add the user account $PW $OPERATION $1 -c "$2" -g users -m # Now fix the password echo $1 $2 $3 >> /script/WBS/useradd.log echo "$3" | pw usermod $1 -h 0 My questions: 1. It it possible (or even necessary) to implement locking when this script runs to take care of any race condition that might lead to master.passwd file corruption? If so, clues/suggestions are welcome. 2. I'll need to capture stderr to the logfile. At what juncture is this suitable? Thanks -Wash http://www.netmeister.org/news/learn2quote.html -- +======================================================================+ |\ _,,,---,,_ | Odhiambo Washington Zzz /,`.-'`' -. ;-;;,_ | Wananchi Online Ltd. www.wananchi.com |,4- ) )-,_. ,\ ( `'-'| Tel: +254 20 313985-9 +254 20 313922 '---''(_/--' `-'\_) | GSM: +254 722 743223 +254 733 744121 +======================================================================+ Aleph-null bottles of beer on the wall, Aleph-null bottles of beer, You take one down, and pass it around, Aleph-null bottles of beer on the wall.