RE: Adding users

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



> -----Original Message-----
> From: shrike-list-admin@xxxxxxxxxx 
> [mailto:shrike-list-admin@xxxxxxxxxx] On Behalf Of Rob Kirkbride
> Sent: Monday, December 22, 2003 9:13 AM
> To: shrike-list@xxxxxxxxxx
> Subject: Re: Adding users
> 
> 
> Steven W. Orr wrote on 22/12/2003 13:50:
> > On Monday, Dec 22nd 2003 at 18:49 +0600, quoth Sanjeewa Wijerathne:
> > 
> > =>Quoting John Haxby <jch@xxxxxxxxxxxxxxx>:
> > =>
> > =>> Tony Arcus wrote:
> > =>>
> > =>> >Anybody got a script that would read a txt type file 
> with user names and 
> > =>> >passwds, adds then and sets up the passwd?
> > =>> >I have schools with hundreds of students and don't 
> what to type this by
> > =>> hand.
> > =>> >  
> > =>> >
> > =>> while read name password; do
> > =>>     useradd -p "$password" "$name"
> > =>> done < file
> > =>> 
> > =>
> > =>If you dont have encrypted passwords in the file, you can 
> use a bit modyfied
> > =>version of 
> > =>John Haxby's script,
> > =>
> > =>while read name password; do
> > =>    useradd  "$name"
> > =>    echo "$password" | passwd --stdin "$name"
> > =>done < file
> > 
> > This will not work. passwd does not read from stdin. It reads from
> > /dev/tty. Probably the easiest way to accomplish what you 
> want is to run 
> > expect. 
> > 
> 
> Last time I checked this did work. See man passwd.
> 
> 
> Rob
> 
# Given a file in the format of username:Real Name:plain-text-password
this will
# create the user and set the password to the stated value.
# ASSUMPTION:  the data file is named "passwd.out"

for i in `awk -F: '{print $1}' passwd.out`
        # This line reads each line from the file, extracts the first
        # field (username) and creates the new user.
do
        j=`cat passwd.out|grep ${i}|awk -F: '{print $2}'`

        useradd -c \""$j"\" ${i}


        # The following line locates the plaintext passwd and resets the
        # password for that named user to the value looked up in the
datafile.

        cat passwd.out|grep ${i}|awk -F: '{print $3}' |passwd --stdin
${i}

Done

Hope this helps,
Lamar


-- 
Shrike-list mailing list
Shrike-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/shrike-list

[Index of Archives]     [Fedora Users]     [Centos Users]     [Kernel Development]     [Red Hat Install]     [Red Hat Watch]     [Red Hat Development]     [Red Hat Phoebe Beta]     [Yosemite Forum]     [Fedora Discussion]     [Gimp]     [Stuff]     [Yosemite News]

  Powered by Linux