Operating System - HP-UX
1753875 Members
7433 Online
108809 Solutions
New Discussion

create users using custom script

 
Pietro84
Advisor

create users using custom script

Hello,

I need to create on my server  +30 users.

 

I want to use a custom shell script that read a txt file and execute "useradd" command. 

I dont want to set a default password for user. I want that on first login user must set/change new password.

 

my txt file is formatted in this fom:

 

#username&group 

user1 group1

user2 group1

user3 group2

.

.

.

 

Any ideas?

 

Thanks.

 

4 REPLIES 4
James R. Ferguson
Acclaimed Contributor

Re: create users using custom script

Hi:

 

What have you tried?  I suggest a search of this community with keywords like 'useradd' and 'script'.

 

In general you can read a file that contains the elements you describe thusly:

 

#!/usr/bin/sh
while read USER GROUP WHATEVER
do
    useradd -G ${GROUP} ${USER}
done < /var/tmp/addusers

...where '/var/tmp/addusers' contains the username and the group to which the user belongs --- one entry per line using whitespace delimited fields.

 

Regards!

 

...JRF...

Pietro84
Advisor

Re: create users using custom script

Hello James, thanks for your reply.

Do "useradd -G group user" force user to set password on first login?
I dont want to set a password for all users.
Pete Randall
Outstanding Contributor

Re: create users using custom script

A quick glance at the useradd man page tells us that "the new login remains locked until the passwd  (see passwd(1)) command is invoked."


Pete
James R. Ferguson
Acclaimed Contributor

Re: create users using custom script


@Pietro84 wrote:

Do "useradd -G group user" force user to set password on first login?
I dont want to set a password for all users.

You are going to need to decide how you want to handle the setup.  The 'useradd' I suggested will create the account but leave it locked until a 'passwd' command is run.  The manpages are your friend!

 

Regards!

 

...JRF...