Operating System - HP-UX
1827881 Members
1251 Online
109969 Solutions
New Discussion

Adding Multiple Users using a script on a Trusted System

 
SOLVED
Go to solution
Ranjith_5
Honored Contributor

Adding Multiple Users using a script on a Trusted System

Hi Experts,

I have got multiple hpus servers on those I need to create nearly 20 new users. Being this is a big talk I would like to use a script for this.

I have the following text files from where I need the inputs to be taken for the user creation. the files are.


logid ( this is the required login ID )
username ( This is the user description required.This is in the format of "Firstname LastName" )



I understand the useradd command will take a unique ID and since i am not using an input file for the same.

I started writing the script as follwos. Dont laugh at me..Im very bad in scripting.Sorry....


#!/usr/bin/sh
#This script will add users taking input from the files logid & username present in the current directory.
clear
echo "\n\n\n"

#groupadd dbuser

for logid in `cat ./logid`

do
for username in `cat ./username`
do

#useradd -c "$username" -g dbuser -m -s /usr/bin/ksh -k /etc/skel -d /home/$logid db$logid
echo "Created user $username\n"

done
done



I hashed the groupadd and useradd commands before actually executing the same. I understand that my looping is not proper.

Can anyone correct my script or recommand a better & easier method to achieve my goal.

Thanks a million in advance.


Regards,
Syam



5 REPLIES 5
Peter Godron
Honored Contributor
Solution

Re: Adding Multiple Users using a script on a Trusted System

Syam,
I would first combine the logid and username file into format:
logid FirstName LastName

then
#!/usr/bin/sh
#groupadd dbuser
#read all the data in the file user.dat
while read data
do
#split the fields up
#first field
logid=`echo $data | cut -d' ' -f1`
#second field onwards
username=`echo $data | cut -d' ' -f2-`

#useradd -c "$username" -g dbuser -m -s /usr/bin/ksh -k /etc/skel -d /home/$logid db$logid
echo "Created user $username"
done < user.dat

Regards
Ranjith_5
Honored Contributor

Re: Adding Multiple Users using a script on a Trusted System

Hi ,

Thanks a lot...But will this work on trusted system? The passwords are stored in TCB database.

Also I wanted the passwords also to be changed with this to a specified one Else.

Else this script wont do the purpose since I have to go to every machine to change the passwords.

Thanks once again.

regards,
Syam
Peter Godron
Honored Contributor

Re: Adding Multiple Users using a script on a Trusted System

Syam,
the second part of the question is a bit more tricky (I think).
According to man useradd:
"If the system is in trusted mode, useradd returns a random password to stdout: the new login is still locked until the passwd command is invoked."
So the problem is to change the password, which I think would be best done using expect.This will then allow you to chnage the password and unlock the account at the same time.
Regards
Ranjith_5
Honored Contributor

Re: Adding Multiple Users using a script on a Trusted System

Hi..,

Can Anyone again explain me how to overcome the problem of changing password using the script on the trusted system.


Regards,
Syam
Ranjith_5
Honored Contributor

Re: Adding Multiple Users using a script on a Trusted System

Hi ,

I modified my script again as follows and it is now able to server my purpose. Thanks for all.

############################################################

#!/usr/bin/sh
groupadd dbuser
rm -f passwords.dat
#read all the data in the file user.dat
while read data
do
#split the fields up
#first field
logid=`echo $data | cut -d' ' -f1`
#second field onwards
username=`echo $data | cut -d' ' -f2-`

useradd -c "$username" -g dbuser -m -s /usr/bin/ksh -k /etc/skel -d /home/db$logid db$logid
/usr/lbin/modprpw -x db$logid >> passwords.dat
echo "Created user $username"
done < user.dat
cat passwords.dat|cut -f2 -d"=">passwords.txt
rm -f passwords.dat

########################################################

The above script stored the initial passwords in a txt file called passwords.txt. I only need to do cat passwords.txt and copy paste to excel.
My Problem is solved.

Closing this thread. Thanks all who replied.

regards,
Syam