Operating System - HP-UX
1833231 Members
2563 Online
110051 Solutions
New Discussion

create user accounts in batch?

 
SOLVED
Go to solution
Joe Alexander_1
Occasional Contributor

create user accounts in batch?

I need to set up 300 users and want to do this from a script. I can create the accounts with useradd, but I would like the password displayed so I can redirect and collect in an output file. Man page says useradd sends "random password" to stdout but it doesn't seem to. This is a trusted system.
4 REPLIES 4
Steven E. Protter
Exalted Contributor

Re: create user accounts in batch?

yes.

Make a list of users, one per line.


sammy
schmo
bagel

call it userlist

script:

while read -r username
do
useradd $username
passwd $username
<< place code here to set password>> without input.
done < userlist


You might wish to have a temporary password list.

SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
MattJ123
Frequent Advisor

Re: create user accounts in batch?

I'd use expect for something like this.. Expect can take variables, and write files and would do exactly what you need.

Just to get you started..
Depot:
http://hpux.cs.utah.edu/hppd/hpux/Tcl/expect-5.42/

Small add user & change password script (untested):
#!/usr/local/bin/expect -f
set timeout -1
spawn $env(SHELL)
match_max 100000
expect -exact "# "
send -- "useradd username\r"
expect -exact "# "
send -- "passwd username\r"
expect -exact "Changing password for username"
New password: "
send -- "new\r"
expect -exact "\r
Re-enter new password: "
send -- "new\r"
expect -exact "\r
Passwd successfully changed\r
# "
expect eof
Kent Ostby
Honored Contributor
Solution

Re: create user accounts in batch?

For each user, do the following:

1) useradd (see above or man (1M)

2) /usr/sam/lbin/usermod.sam -F -p "" account_name

This will force the user to enter a new password when they log in the first time.

Best regards,

Kent M. Ostby
"Well, actually, she is a rocket scientist" -- Steve Martin in "Roxanne"
Joe Alexander_1
Occasional Contributor

Re: create user accounts in batch?

Thanks for the variety of solutions. The solution I chose was to use useradd to create the account, then use the UNSUPPORTED /usr/lbin command modprpw -x to set a temporary password, which is echoed to stdout.