[lug] group perm nightmare

chris fool at dfw.net
Fri Oct 4 14:14:22 MDT 2002


On Fri, Oct 04, 2002 at 01:15:14PM -0600, Warren Sanders wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
> 
> I am migrating users from an old mandrake system to a new RH8.0 system.It 
> contains a mix of users with 'users' as the group.  I'd like to tie this 
> down a bit by making both owner:group the same recursivly as a new useradd 
> would by default.  Anyone have a script for this?


#!/bin/sh
#requires reasonable setting of $basegroup to the number gid's should start
#  with for newly created (single-user) groups.
#assumes all users have homedirs named after their accounts.  modify & run
#  multiply if you have >1 parent directory for home directories
#  (ie /home1. /home2).  don't forget to change $basegroup when re-running.
#doesn't chgrp files that are not already in group users, and shouldn't add
#  new groups for users already created properly.
#need to munge-your-own password file.  the sed command below is close but
#  my sed skills aren't too sharp and my favorite perl ref isn't handy
#no warranty express or implied.

basegroup=510
cd /home
for i in * ; do
	if ! grep "^${i}:" /etc/group ; then
		echo "$i:x:$basegroup:" >> /etc/group
#		sed "s/^${i}:x:([^:]*):[^:]*/^${i}:x:\1:$i/" /etc/passwd
		basegroup=`expr $basegroup + 1`
	fi
	find $i -group users -exec chgrp $i {} \;
done



More information about the LUG mailing list