Find the answer to your Linux question:
Results 1 to 3 of 3
This script is supposed to read some data about students from a file (first name, last name, and a group), and should create accounts for each of them, in the ...
  1. #1
    Just Joined!
    Join Date
    May 2007
    Posts
    1

    useradd --password... what could be wrong?

    This script is supposed to read some data about students from a file (first name, last name, and a group), and should create accounts for each of them, in the form firstname.lastname, also setting the real name field, and the password should be set to the name of the group. All the information are extracted correctly, and I don't see any errors in the syntax. However, useradd exists with code 2 (invalid syntax). The code is
    Code:
    while read line
    do
        nume=`echo $line | cut -d " " -f 1 | tolower` # tolower is another script that uses sed to turn uppercase->lowercase
        prenume=`echo $line | cut -d " " -f 2 | tolower`
        grupa=`echo $line | cut -d " " -f 3`
        parola=`encript $grupa` # this is a program i made that encrypts passwords using crypt()
        fullname=`echo $line | cut -d " " -f 1,2`
    
        useradd -c \"$fullname\" -p $parola $prenume.$nume
        echo "L-am citit pe $prenume.$nume"
    done < $fisier
    I'm guessing it's because $parola contains "$1$salt$hash". I tried slicing the password, and using \$1\$salt\$$password, but it's still not working. Any clues?

  2. #2
    Linux User
    Join Date
    Aug 2006
    Posts
    458
    how bout trying double quotes around $parola

  3. #3
    Just Joined! cfajohnson's Avatar
    Join Date
    May 2007
    Location
    Toronto, Canada
    Posts
    52
    Quote Originally Posted by TehLamz0r View Post
    This script is supposed to read some data about students from a file (first name, last name, and a group), and should create accounts for each of them, in the form firstname.lastname, also setting the real name field, and the password should be set to the name of the group. All the information are extracted correctly, and I don't see any errors in the syntax. However, useradd exists with code 2 (invalid syntax). The code is
    Code:
    while read line
    do
        nume=`echo $line | cut -d " " -f 1 | tolower` # tolower is another script that uses sed to turn uppercase->lowercase
        prenume=`echo $line | cut -d " " -f 2 | tolower`
        grupa=`echo $line | cut -d " " -f 3`
        parola=`encript $grupa` # this is a program i made that encrypts passwords using crypt()
        fullname=`echo $line | cut -d " " -f 1,2`
    
        useradd -c \"$fullname\" -p $parola $prenume.$nume
        echo "L-am citit pe $prenume.$nume"
    done < $fisier
    I'm guessing it's because $parola contains "$1$salt$hash". I tried slicing the password, and using \$1\$salt\$$password, but it's still not working. Any clues?

    The problem is probably in not quoting variables:

    Code:
    useradd -c "$fullname" -p "$parola" "$prenume.$nume"
    You can make the script much more efficient by getting rid of all those calls to cut, and only calling tolower once:

    Code:
    IFS=' '
    set -- $line
    fullname="$1 $2"
    prenum=$3
    set -- `printf "&#37;s\n" "$line" | tolower`
    nume=$1
    grupa=$2

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...