LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   Users script (https://www.linuxquestions.org/questions/linux-general-1/users-script-791301/)

kopper27 02-24-2010 12:15 PM

Users script
 
hi guys

I have pretty simple basic script well 2 scripts to create users

it basically reads an usersinfo file with this structure

FirstName and Last Names - CompanyName LoginID UID

Code:

Charlie Mareuz Yander - CompanyName logind 600
Ana Benz Squel - BAC CompanyName loginid 601

and uses an useradd command to just create the user

Code:

#!/bin/bash
while read -r l1 l2 l3 l4 l5 l6 l7
do
useradd -c "$l1 $l2 $l3 $l4 $l5" $l6 -u $l7
done <usersinfo
cat /etc/passwd

After that manually I have to set the password for every user
so for 4 users I have to use passwd loginID 4 times

I need a way to add to my script how to read passwords in that same file (usersinfo) and script that instead of doing manually

I've tried but since the password is asked twice I don't know how to script that

would be like

Code:

#!/bin/bash
while read -r l1 l2 l3 l4 l5 l6 l7
do
useradd -c "$l1 $l2 $l3 $l4 $l5" $l6 -u $l7
passwd $16
???? don't know how to read from the file the password I want for this user
done <usersinfo
cat /etc/passwd

any idea?

thanks a lot

irmin 02-24-2010 12:31 PM

passwd(1) offers the option --stdin to read the password from stdin:
Code:

echo $password | passwd --stdin $l6

kopper27 02-24-2010 01:19 PM

Quote:

Originally Posted by irmin (Post 3875316)
passwd(1) offers the option --stdin to read the password from stdin:
Code:

echo $password | passwd --stdin $l6


thanks a lot that's all I needed
:hattip:


All times are GMT -5. The time now is 03:11 AM.