- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: how to create many users in a single step
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
11-13-2003 01:18 AM
11-13-2003 01:18 AM
how to create many users in a single step
I have 2 hpux server.
Server 1 has 200 users configured with their home and profiles..
Server 2 has his 200 users...
I have to add on server 1 ALL the users of server 2...creating all the home and profiles.
I'm thinkin to copy all the home dir (tar and copy) preserving permissions on files but I don't know how to create 200 users!
Should I use useradd 200 times?!? ;-(
Is there any way to batch-create many users in a single step?
Thanks in advance!
Emanuele
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-13-2003 01:20 AM
11-13-2003 01:20 AM
Re: how to create many users in a single step
If you copy over the home dirs for the users, and you aren't using shadow passwords, you can just copy the entries in /etc/passwd for the 200 users from server 1 to server 2. I've done that before. That way the users have the same passwords.
JP
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-13-2003 01:34 AM
11-13-2003 01:34 AM
Re: how to create many users in a single step
A better way would be to merge the password files into NIS if you want both servers to keep working for the users. This will also keep the passwords synchronised.
But if you want to just merge, it can be done with a script too. Simplest way would be to NFS mount the /home directory of server 2 on server 1, copy /etc/passwd from server 2 to another location on server1, clean out all users that shouldn't be copied (root, lp, etc) and then script creating the users and homedirectories. If you use shadow password file, als copy that file from server 2 to server 1 (of course not to /etc) and you can put the crypted passwords in the active shadow file on server 1.
If you want, I can give a sample of the script to use, but need some more info on the questions/points I started with before doing a thing like that.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-13-2003 01:51 AM
11-13-2003 01:51 AM
Re: how to create many users in a single step
I'm not using NIS and I'm not using shadows.
So I could merge the /etc/passwd files...but I'm afraid There could be broblem with duplicated names and duplicate user id and group id.
May be a script that is able to add every user reading from the original /etc/passwd could be better.
I could copy the home structure (tar with attributes) and add the users with the script?
Emanuele
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-13-2003 02:05 AM
11-13-2003 02:05 AM
Re: how to create many users in a single step
You can either
1. Merge the password files and then check for uniqueness:
To check for duplicate username, use
awk -F: '{print $1}' /etc/passwd|sort|uniq -d
To check for duplicate id, use $3, for gid, use $4 (but duplicate group ids are normal).
or
2. Use awk to generate a whole load of useradd statements from the first passwd file, and run on the 2nd system
useradd will tell you if you are trying to add a user that already exists.
-- Graham
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-13-2003 02:06 AM
11-13-2003 02:06 AM
Re: how to create many users in a single step
One other thing: /etc/group should probably be taken into account too.
In pseudo scripting it would become something like this:
cat passwd.server2 | while read line
do
username=`echo $line | cut -d: -f1`
passwd=`echo $line | cut -d: -f2`
homedir=`echo $line | cut -d: -f3`
:
:
if grep -q $username /etc/passwd
then
echo "User already exists... Skipping"
else
groupname=grep $groupid group.server2 | cut -d: -f1`
if grep -q $groupname /etc/group
then
:
else
groupadd $groupname
fi
useradd -d $homedir -s $loginshell -c "$realname" -g $groupname $username
(cd /home.server2 ; tar cf - $username) | (cd /home ; tar xf -)
chown -R $username:$groupname $username
fi
done
Some things miss and it depends on homedirectories using the same name as the login name, but it is a start. I'm sorry I don't have time to give a better, detailed version right now.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-13-2003 02:33 AM
11-13-2003 02:33 AM
Re: how to create many users in a single step
You should be aware of, when using the method with copying user home directorys from one server to another the users in the password and group files must be identic on the two servers. If you already have users/groups on the second server with the same user or group id you will get problems.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-13-2003 03:19 AM
11-13-2003 03:19 AM
Re: how to create many users in a single step
Write the first row and duplicate for 200 times, after change the necessary and save it.
(some procedure for group, in /etc/group)
Bruno