- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: Need to change User IDs and GROUP IDs for many...
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-26-2004 05:29 AM
02-26-2004 05:29 AM
I have a situation where I need to change the User IDs and Group IDs for about 250 users. This came about as a result of a company merger. Many of the ID's overlap so that adds to the confusion. Right now, I change one user and then do a find changing all his files to the new User ID and Group ID. The problem is that the find takes about 40 minutes per user to complete. At this rate, I'll be doing this until I retire. Can anyone think of a better, faster way?
Thanks in advance,
John Wolfe
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-26-2004 05:37 AM
02-26-2004 05:37 AM
Re: Need to change User IDs and GROUP IDs for many users.
I would suggest to run 'find' only once and collect the uid/gid information of all the files into one file. Then you can use that file to find out the files|directories owned by a user and simply work on them to change. For ex.,
find / -type f -o -type d |xargs ll -d > /somewhere/userlist
This will also help you to backout the change easily and you don't have to run find again and again for each user.
-Sri
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-26-2004 05:38 AM
02-26-2004 05:38 AM
Re: Need to change User IDs and GROUP IDs for many users.
ls -1 -r / | grep username > /tmp/file
while read -rr aa
do
chown newid:newgroup $aa
done < /tmp/file
SEP
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-26-2004 05:45 AM
02-26-2004 05:45 AM
SolutionI would make two tables to do the translations with this format:
OLDUID NEWUID User Optional_Comments
The other table should be the same except is should list the GID's.
OLDGID NEWGID Group Optional_Comments
Actually, only the OLDUID and NEWUID columns need to be meaningful.
You should then be able to loop thru your sorted filelist and apply the changes. Because the filelist is sorted in UID/GID order, it makes sense to cache the last lookup so that you don't need to rescan your translation tables each time.
You also need to apply usermod based upon your UID translation table but that is very simple.
This should be done during a scheduled maintenance window because changing UID/GID's "on the fly" is going to wreak havoc upon any running users.
If this were me, I'd do it in Perl.
Final thought: Don't forget when you are writing these here scripts that some of them there filenames might have spaces in them. I ain't saying it's a good idea but it does not mean that they ain't out there just waiting to clobber some poor unsuspecting script.
Food for thought, Clay
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-26-2004 06:37 AM
02-26-2004 06:37 AM
Re: Need to change User IDs and GROUP IDs for many users.
uid
and optionally sorts the output.
With a little "cut 'n paste" this was about 5 minutes of Perl complete with a Usage() subroutine.
invoke it like this:
find.pl -s /home /dog /cat /platypus > /var/tmp/filelist
or find.pl -u for usage. If no directories are specified it starts at the CWD. -s says sort the output.
This should get you started and note the intentional
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-26-2004 06:41 AM
02-26-2004 06:41 AM
Re: Need to change User IDs and GROUP IDs for many users.
In your script that does the UID/GID translations, I would also not change files with UID's below a certain value; e.g. <= 100. Well disciplined admins start normal UID's no lower than 101; the others are reserved for system stuff.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-26-2004 09:34 AM
02-26-2004 09:34 AM
Re: Need to change User IDs and GROUP IDs for many users.
A. Clay, you made a very good point about spaces in filenames. Frankly, I had not even considered that problem.
Thanks,
John Wolfe
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-27-2004 06:02 AM
02-27-2004 06:02 AM
Re: Need to change User IDs and GROUP IDs for many users.
I used Perl's internal chmod for everything except symbolic links. Those are handled with a call to the chmod -h gid:uid command. I could have had you load a Perl module that include lchmod but this method requires no extra modules. I figure that you have so few symlinks which actually need translating that the overhead of the system() call will be negligible.
Use it like this assuming that your UID table is called "uids" and the GID translation table is called "gids".
fixuids.pl -U uids -G gids -e 100 -v < /var/tmp/filelist
Invoke as fixuids.pl -u for full usage.
This should be very close but use at your own risk.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-27-2004 07:45 AM
02-27-2004 07:45 AM
Re: Need to change User IDs and GROUP IDs for many users.
I've been looking over your script and I think I've found an error although perl -c fixuids.pl says that the syntax is ok.
$cc = do_1_file($s_in[0],$s_in[1],$s_in[2],
($s_in[3] eq SYMLINK));
I think you need an if statement to use "eq". You can't use it like ($s_in[3] eq SYMLINK) can you?
Please answer soon or any other Perl experts out there feel free to answer for A. Clay. I want to fixthe user id's this weekend.
Thanks,
John Wolfe
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-27-2004 07:58 AM
02-27-2004 07:58 AM
Re: Need to change User IDs and GROUP IDs for many users.
($s_in[3] eq SYMLINK) evaluates to true (non-zero) or false (0). Given that SYMLINK is a constant for the string '12', we are testing $s_in[3] to see whether or not it is '12'. Octal 12 is the file type (actually mode = 0120000) that corresponds to symbolic links.
All we need to know is whether or not this file is a symbolic link. The expression is a rather standard method to evaluate an expression as a boolean.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-27-2004 08:19 AM
02-27-2004 08:19 AM
Re: Need to change User IDs and GROUP IDs for many users.
John Wolfe