Operating System - HP-UX
1824976 Members
3338 Online
109678 Solutions
New Discussion юеВ

Adding multiple user accounts

 
SOLVED
Go to solution
B Wade Moll
Frequent Advisor

Adding multiple user accounts

I was given a list of about 40 new users to add to 25 servers. What I would like to do is create a text file with the username (users.dat) and run a script to add them to the server.

I have very little knowlege of ksh programming, does anyone have a script that does something along those lines?

Thank you !!
4 REPLIES 4
Craig A. Sharp
Super Advisor
Solution

Re: Adding multiple user accounts

what exactly is in the file?

You can take a simple route like

for i in 'cat users.dat'
do
useradd -m $i
done

Then you would have to set the passwords. I used expect to do a script that would add the user then add a standard password, but most systems dont have Expect.

Craig
James R. Ferguson
Acclaimed Contributor

Re: Adding multiple user accounts

Hi:

You can do something like this:

# cat addusers
#!/usr/bin/sh
OLDIFS=${IFS}
IFS=":"
while read USER UID GID GECOS HOMEDIR THESHELL
do
echo useradd -u ${UID} -g ${GID} -c "\""${GECOS}"\"" -d ${HOMEDIR} -m -s ${THESHELL} ${USER}
done < newusers
IFS=${OLDIFS}
exit 0

# cat newusers
wade:500:20:wade at work:/home:/usr/bin/sh
wade2:501:20:wade at home:/home:/usr/bin/sh

...run as:

# ./addusers

Regards!

...JRF...
Craig A. Sharp
Super Advisor

Re: Adding multiple user accounts

Sorry, this is assuming that the file is in the form

username1
username2
username3

Craig
B Wade Moll
Frequent Advisor

Re: Adding multiple user accounts

Thank you .. just saved me a week of sam work !!