- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: How do you add users from a file ?
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
03-02-2004 01:36 AM
03-02-2004 01:36 AM
xxx:N/ySsbm7JksgM:108:20:Nick smith,LOC MIS,,:/home/xxx:/usr/bin/ksh
yyy:3TZhn7hgulQyM:113:108:Tom jones,PTD ,,:/home/yyy:/usr/bin/ksh
zzz:pxLMqyNjqx1Wk:114:105:Mike greeb,WSD MIS,,:/home/zzz:/usr/bin/ksh
...
more...
What's the quickest way to add them to server "B"? Isn't there a command to add users (I normally use SAM for one user at a time.)
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-02-2004 01:37 AM
03-02-2004 01:37 AM
Re: How do you add users from a file ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-02-2004 01:41 AM
03-02-2004 01:41 AM
Solutionhttp://forums1.itrc.hp.com/service/forums/questionanswer.do?threadId=478688
Regards,
Robert-Jan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-02-2004 06:07 AM
03-02-2004 06:07 AM
Re: How do you add users from a file ?
for i in `cat /home/xyz/users`
do
remsh $(Remote host) "/usr/sbin/useradd -g "groupname" -d /home/"$i" -m "$i""
done
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-02-2004 07:37 AM
03-02-2004 07:37 AM
Re: How do you add users from a file ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-02-2004 08:41 AM
03-02-2004 08:41 AM
Re: How do you add users from a file ?
The following approach may be safer as it basically uses user*|group* commands. Take backup of your /etc/passwd and /etc/group files before you attempt to do anything. A make_tape_recovery may help you in case if you get into trouble.
I am putting some scripting here but that is not tested completely. It's only to give you an idea.
Basically this is looking like a passwd file. So, you can grab all the fields and use them with useradd command. Set the password using usermod.sam command. This approach will work whether this system is trusted or not. However, there are couple of things to be done before you can actually use useradd command.
1. Find out all the groups that may be new to the system.
//
for GRP in $(awk '{FS=":";print $4}' your_file|sort |uniq)
do
grep -q ":${GRP}:" /etc/group
if [ $? = 0 ]
then
echo "$GRP" >> group.exists
else
echo "$GRP" >> group.create
fi
done
//
group.create file contains all the groups that have to exist before you can add the users. Modify the file to look like this
108:group1
105:group2
etc., and run
//
while read LINE
do
GID=$(echo $LINE|awk '{FS=":";print $1}')
GROUP=$(echo $LINE|awk '{FS=":";print $2}')
groupadd -g $GID $GROUP
done < group.create
//
2. Once the groups are created, then you run the following script to add the users. The errors and output of the script will be logged into useradd.log. You can view it and see the errors and fix them. Since you already have the encrypted passwords, you can usermod.sam to add them into password registry.
//
while read LINE
do
USER=$(echo $LINE |awk '{FS=":";print $1}')
PASS=$(echo $LINE |awk '{FS=":";print $2}')
UID=$(echo $LINE |awk '{FS=":";print $3}')
GID=$(echo $LINE |awk '{FS=":";print $4}')
GECOS=$(echo $LINE |awk '{FS=":";print $5}')
HOUSE=$(echo $LINE |awk '{FS=":";print $6}')
SHELL=$(echo $LINE |awk '{FS=":";print $7}')
printf "%-30.30s" "Working on $USER "
useradd -u $UID -g $GID -d $HOUSE -s $SHELL -c "$GECOS" -m -k /etc/skel $USER >> u
seradd.log 2>&1
RESP=$?
if [ $RESP = 0 ]
then
/usr/sam/lbin/usermod.sam -p "$PASS" $USER
STATUS="-DONE"
else
echo "Addtion of $USER failed with return code $RESP" >> useradd.log
STATUS="-FAILED"
fi
printf "${STATUS}\n"
done < your_file
//
-Sri
PS: Use it at your risk.