Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 26 Apr 2004 13:49:37 +0300
From:      Odhiambo Washington <wash@wananchi.com>
To:        freebsd-isp@freebsd.org
Subject:   pw and file locking
Message-ID:  <20040426104937.GA58605@ns2.wananchi.com>

next in thread | raw e-mail | index | archive | help
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:

<quote>
#!/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    <wash@wananchi.com>
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.



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20040426104937.GA58605>