Ldap – bulk swap uidNumber/gidNumber


We currently have LDAP servers in Dev env. and staging/prod env. Both are not coupled and accounts are created manually. So the uids are same but the uidNumber and gidNumber are different across these two envs.

I am trying to upgrade to 389 DS and setup replication, so that users are sync'ed from Dev to staging/prod ldap servers without needing an admin. But doing that will involve changing the uidnum/gidnum but the userid will stay same. I wrote a script which gives me the list of users with conflicting uidnumbers and it says I have around 250 users like that. Sample:

amauer STG:2596 | DEV:2581  conflictID:aling
aling STG:2581 | DEV:2678  conflictID:blsow
bslow STG:2678 | DEV:2625  conflictID:krusso

As you can see amauer with staging uidNumber=2596 has 2581 in dev. If I go ahead and change it via script below, I would mess up files that belong to amauer when i do the same on aling user. As at that time, amour and aling will have same uidNumber.

cat "$chownlist" | xargs -0 sudo chown $user
cat "$chgrplist" | xargs -0 sudo chown :$group
sudo rm "$chownlist" "$chgrplist"

Did anyone have similar problem while bulk changing file owner/group? Some kind of sorting mechanism which will come up with a list that

This project will give me 2-3hrs extra time every week and automation is OUR profession. 🙂

Any ideas??


Best Answer

Try this as well to do the chown/chgrp in one step:

find / -uid $OLDUID -exec chown $NEWUID '{}' +
find / -gid $OLDGID -exec chgrp $NEWGID '{}' +