0

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??

Thanks

1
  • 1
    I just got the Eureka bulb over my head. :) Looks like the user files are mostly contained in homerdir with same name as uid. So I am thinking I should come up with a script which checks the homedir name and changes the uid/gid of files under it to the same as DEV. But still I don;t want to overlook anything as this is PRODUCTION & PROD, slightest mistake can cost my life. :) Jun 24, 2010 at 22:22

2 Answers 2

2

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

find / -uid $OLDUID -exec chown $NEWUID '{}' +
find / -gid $OLDGID -exec chgrp $NEWGID '{}' +
6
  • Thanks, but the problem is bulk update and resolve conflicts. This brings back the classic example of swapping values of two variables with a temp var. What do you think of my problem? Jun 25, 2010 at 20:44
  • 1
    It's kind of vague exactly what your problem is... from what I can tell you don't need to swap anything, you're just picking a 'primary' system and changing any UIDs on the other system that conflict before merging.
    – MikeyB
    Jun 27, 2010 at 1:44
  • My main goal is to have same uid/gid number for all users across all env. I will use LDAP for that and I can just import an ldif to the server side. The client hosts will have the old uid/gid. Why swap? Because at a point in the chown two users will have same uid. Take for example (see code above) If users amauer & aling have files on same host, after changing the uid for amauer, $OLD_UID for aling and $NEW_UID for amauer will be same. Then executing chown will make aling own amauer files. The new uid & old uid overlap and a chain effect will ust mess up file permissions. Am I wrong here? Jun 28, 2010 at 14:47
  • So at the moment, there exist hosts where two users with identical UIDs both have files? I hope everything's in /home.
    – MikeyB
    Jun 28, 2010 at 15:12
  • Just so that I don't sound more stupid. Does the find command traverse thru the files that was changed/operated in the whole process? So if I find a value and change the name of the file/permissions will it come up again in search result? Jun 28, 2010 at 15:50
0

I have found one way of doing this but looks like it will only partially solve it. Number of conflicting users: 250 Number of hosts with homeDirs: 50

seed for script.

amauer:2670:1010:2082:1010
aling:2082:1010:2871:1010
bslow:2871:1010:2447:1010

Script

    for i in `cat hosts.txt`; do
        for j in `cat uid-gid_seed.txt`; do
            user_id=`echo $j | cut -d: -f 1`
            old_uid=`echo $j | cut -d: -f 2`
            old_gid=`echo $j | cut -d: -f 3`
            new_uid=`echo $j | cut -d: -f 4`
            new_gid=`echo $j | cut -d: -f 5`
            echo "--------------------"
            echo $i
            echo
            ssh $i `sudo /usr/bin/find -path "/home/$user_id" -user $old_uid -exec chown $new_uid '{}'`;
    done;
   done

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .