Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 23 Aug 2001 09:50:54 +1000
From:      Tony Landells <ahl@austclear.com.au>
To:        Odhiambo Washington <wash@wananchi.com>
Cc:        FBSD-Q <freebsd-questions@FreeBSD.ORG>
Subject:   Re: One for the script gurus 
Message-ID:  <200108222350.JAA20794@tungsten.austclear.com.au>
In-Reply-To: Message from Odhiambo Washington <wash@wananchi.com>  of "Wed, 22 Aug 2001 16:36:49 %2B0300." <20010822163649.B98728@ns2.wananchi.com> 

next in thread | previous in thread | raw e-mail | index | archive | help
Hi!

One of the things I like about the Bourne shell derivatives is that
you can feed a loop with multiple values:

awk -F: '{ print $1, $3, $4, $6 }' | while read user uid gid home; do
	# You may want to filter out some values here
	# such as: users with a uid < 1000 or > 32000;
	# or users with a home directory of /

	echo "Making home for ${user}

	# For anything we haven't pruned:
	mkdir ${home}

	# Do you need to copy any files in?  If so, do it here.
	# For example:
	cd /usr/share/skel
	for file in `ls | awk -F. '{ print $2 }'`; do
		cp dot.${file} ${home}/.${file}
	done 
	
	# And then, maybe...
	chown -R ${uid}:${gid} ${home}

	# And finally, if necessary, "lock" the directory
	# by setting whatever mode you desire
done

Of course, there are some minor efficiencies that could be made, like
creating the file list from /usr/share/skel outside the loop and so
forth, but given that this is basically a "once off" type thing I'd
like to maximise readability.

Cheers

Tony
-- 
Tony Landells					<ahl@austclear.com.au>
Senior Network Engineer				Ph:  +61 3 9677 9319
Australian Clearing Services Pty Ltd		Fax: +61 3 9677 9355
Level 4, Rialto North Tower
525 Collins Street
Melbourne VIC 3000
Australia



To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-questions" in the body of the message




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