Operating System - HP-UX
1837970 Members
2793 Online
110124 Solutions
New Discussion

Re: changing uid on many system

 
SOLVED
Go to solution
Sachin Patel
Honored Contributor

changing uid on many system

Hi

We have few hunders users and tens of systems.
We are using nis for logging. This was setup long time ago so uid was started below 100 and uid was started below 50.
We would like to change uid and gid of users. whenever I change something on nis and push the map out it is going to be problem as all the files belong to that new uid is not getting updated automatically.

What is the best way to achive this?

I have write script but that hangs and is not working proparly with nfs file system ( I actully do not want to chage anything on nfs though).


Thanks
Sachin
Is photography a hobby or another way to spend $
12 REPLIES 12
Geoff Wild
Honored Contributor
Solution

Re: changing uid on many system

Hmnnn...why not just run a find command:

find $4 -user $1 | xargs chown $2:$3 {}

$4 is filesystem
$1 is old uid
$2 is new uid (or just the user id)
$3 is gid (or just groupname)

Rgds...Geoff
Proverbs 3:5,6 Trust in the Lord with all your heart and lean not on your own understanding; in all your ways acknowledge him, and he will make all your paths straight.
Sridhar Bhaskarla
Honored Contributor

Re: changing uid on many system

Sachin,

You have a huge task in front of you. Changing uids can break the things particularly on NFS as all of a sudden you will find errors like 'permission denied' etc.,

One way is run 'find' command only once and capture enough information and then use that information to change the ownerships. ownerships.

find / |xargs ll -d > /somewhere/filelist.

If the argument list is too long, you can seperate it by filesystem wise. Then you can find the files owned by a particular user and change ownerships on only those files. I got couple of hiccups but got successful before.

Alternatively, using the common method, run find for every user.

You can use '-local' option in find to avoid changing permissions on the nfs filesystems. However, it will not stop traversing through NFS directories. The otherway is to selectively use -fsonly for both hfs and vxfs. But again there are limitations to it. Look at the man page.

find / -local -user $uid |xargs chown user:group

-Sri
You may be disappointed if you fail, but you are doomed if you don't try
Sachin Patel
Honored Contributor

Re: changing uid on many system

Geoff and Sridhar
You are saying that I should use find command inside the script and use that recursively correct?

Sachin
Is photography a hobby or another way to spend $
Geoff Wild
Honored Contributor

Re: changing uid on many system

I would test it with 1 user - the find that is....I'm not a perl wiz - there may be something amis in your script - that's why I suggested the "simple" way....

I would run it for each user....

I just used the $4, etc in case you want to script it.

Srindhar brings up a good point - you may want to produce a list instead - that way, is you have to go back - you can see what they were - or like he says, use that list to run the chown against:

for i in `cat filelist`
do
chown userid:group $i
done

Rgds...Geoff
Proverbs 3:5,6 Trust in the Lord with all your heart and lean not on your own understanding; in all your ways acknowledge him, and he will make all your paths straight.
A. Clay Stephenson
Acclaimed Contributor

Re: changing uid on many system

The ideal way to do this would be to do a find for each system and produce a list but not just any list. You want a list that is sorted in uid,gid order. Then for every uid:gid tuple you can spawn a single chown command using xargs. You definitely want to avoid multiple passes with find.

If it ain't broke, I can fix that.
Sachin Patel
Honored Contributor

Re: changing uid on many system

Good idea but not fisable in my environment

We have 100+ system and 700Tb+ space you can imagine what happens if try to do it by hand.

I have run this script on linux and hps works fine in most cases but gets hang or gets stuck in loop sometime. So far I am the test user.

Any other idea?
Is photography a hobby or another way to spend $
Sachin Patel
Honored Contributor

Re: changing uid on many system

Clay, Geoff and Sridhar

My idea was to change one user at a time.
run script overnight on all the system by passing old uid,new uid so script will find anything that is old uid and change to new.

Then pick another user again and do same processess. I will not be able to change all at same time.

But if I finds anyother idea better thenthis I am ready to implement it.

Sachin
Is photography a hobby or another way to spend $
A. Clay Stephenson
Acclaimed Contributor

Re: changing uid on many system

Multiple passes is the non-optimal (dumb) way to do that. The idea is to make one find pass and build a list. Sort it in gid, uid order. Next read in each line using awk/Perl/ or even shell and make your uid and gid substitions to greate a new list that has gid, uid, filename as fields. You then make a final pass that generates a series of chown commands. This will run tens of times faster than your method. With only a little extra work you could remsh the whole thing and execute perhaps 10 of these at a time in backgroup. You would then issue a wait which would wait until all 10 of these finished and spawn a new bunch.

You should think of this not as a uid/gid change process but a learning process.
If it ain't broke, I can fix that.
Sachin Patel
Honored Contributor

Re: changing uid on many system

Clay looks like you are right. I should look this task differently.
I now have another eye it just make me realize that if I change one of the programmer's uid and If I can't change his files with new uid all the programm will be broken. I have to have list ready and as soon as I change uid on nis I will have to change listed files.

I fixed my script now so it is working on sun, hp and linux but not fast enough. It is taking 10 to 15 minutes per system. But If I have list of files ready It can be done within a minute.


Thanks
Sachin
Is photography a hobby or another way to spend $
Sachin Patel
Honored Contributor

Re: changing uid on many system

Thanks guys,
Now I have two script
1. goes to datacenter runs find command on local disk and finds files belong to particular user and generat a file.
Takes around 10 hours.

2. runs chown on that listed file only.
Takes less then half hour.

Thanks
Sachin
Is photography a hobby or another way to spend $
Sridhar Bhaskarla
Honored Contributor

Re: changing uid on many system

Hi Sachin,

A find command will touch everyfile anyway. Then why wouldn't you run it to gather the information for all the files?.

If you don't want it, then atleast you can club multiple users in one shot.

find / -local \( -user user1 -o -user user2 -o -user user3 \) |xargs ll -d >> /somewhere/list

Now list has files of user1, user2 and user3. Now you can seperate each user into a different list and have the ownerships changed. You can automate it too.

-Sri
You may be disappointed if you fail, but you are doomed if you don't try
Sachin Patel
Honored Contributor

Re: changing uid on many system

sridhar,
I have put that provision in place so I can collect info upto three user.
But most probable it will not work because of space issue.
I have terrabyte of space with each system and only small /tmp file where I am collecting information.
I can't use other file system as they all low in space and has no uniq nameing.
Also I have to run one script for hp-sun-linux too.

Thanks for your help and ideas for pointing me in right direction.

Sachin
Is photography a hobby or another way to spend $