1833760 Members
2183 Online
110063 Solutions
New Discussion

need useradd scripts

 
SOLVED
Go to solution
Jan Shu
Regular Advisor

need useradd scripts

Hi All,

I need a script to create 3 hundreds of new user accounts and their home directories at /oralog/ and 3 subfolders (permissions is 775) under each home directory. Can you please help? Thank you.

Best Regards,
Jan Shu
8 REPLIES 8
Mel Burslan
Honored Contributor

Re: need useradd scripts

assume usernames are contained in a file /tmp/userlist

for u in `cat /tmp/userlist`
do
useradd -d /oralog/$u -m $u
mkdir /oralog/$u/directory1
mkdir /oralog/$u/directory2
mkdir /oralog/$u/directory3
chown $u /oralog/$u
chmod 755 /oralog/$u
chmod 775 /oralog/$u/*
echo $u " created successfully."
done

hope this helps
________________________________
UNIX because I majored in cryptology...
Steven E. Protter
Exalted Contributor

Re: need useradd scripts

Shalom,

http://forums1.itrc.hp.com/service/forums/questionanswer.do?threadId=51050

Two more threads in that thread.

The largest concentration of scripts sysadmins can't live without in ITRC.

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
Jan Shu
Regular Advisor

Re: need useradd scripts

Hi Steven,

Thanks for the reply. This link http://forums1.itrc.hp.com/service/forums/questionanswer.do?threadId=51050 web page is more than 1 mile long. Can you please kindly point out the sessions where I can find useradd scripts? I searched the keyword "useradd" but find no match.

Thanks again.

Best Regards,
Jan Shu
Marek Mahut
Advisor

Re: need useradd scripts

Hello,

Make a new text file (here ./text_file_with_users.txt) with list of user like this:

...
username1 password1 mygroup1
beny We5gG5^qw@ users
username2 password2 mygroup2
...

and run this script:

#!/usr/bin/ksh

NEW_USERS="./text_file_with_users.txt"
HOME_BASE="/oralog/"

cat ${NEW_USERS} | \
while read USER PASSWORD GROUP
do
useradd -g ${GROUP} -p ${PASSWORD} -m -d ${HOME_BASE}${USER} ${USER}
done
"If I ever find out about someone sacrificing quality in order to meet a shipment schedule, I will personally have him fired." -- Dave Packard
Jan Shu
Regular Advisor

Re: need useradd scripts

Hi Mel, I ran your script and it works, but what is the password for the new user accounts? Thanks.

Hi Marek, I don't think useradd command has -p option. Can you please check? Thanks.

Have a good one.

Regards,
Jan
Mel Burslan
Honored Contributor
Solution

Re: need useradd scripts

Jan,

When the user gets created, there is no password assigned to the user. And user can not login before a password is assigned.

Depending on your trusted or non-trusted security status, there are few options that you can set the initial passwords to a certain string. The common and unsupported way of mass changing the password, which you can use regardless if you are in a trusted or non-trusted computing mode.

all you have to do is to manually change the password for any one user. Grab the encrypted password string from this users record:

a) if non-trusted
enc_pwd=`grep $username /etc/passwd|cut -d: -f2`

b) if trusted
enc_pwd=`grep u_pwd /tcb/files/auth/$(echo $username|cut -c1)/$username|cut -d= -f2 |cut -d: -f1`

then run this little script again

for user in `cat /tmp/myuserfile`
do
/usr/sam/lbin/usermod.sam -p $enc_pwd $user
/bin/passwd -f $user #force user to change on first login
echo "password of user $user has been changed"
done


________________________________
UNIX because I majored in cryptology...
Jan Shu
Regular Advisor

Re: need useradd scripts

THANK YOU ALL FOR HELPING ME ON USERADD SCRIPT.
Jan Shu
Regular Advisor

Re: need useradd scripts

Case is close. Thanks.