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 ...
- 05-19-2007 #1Just 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
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?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
- 05-20-2007 #2Linux User
- Join Date
- Aug 2006
- Posts
- 458
how bout trying double quotes around $parola
- 05-21-2007 #3
The problem is probably in not quoting variables:
You can make the script much more efficient by getting rid of all those calls to cut, and only calling tolower once:Code:useradd -c "$fullname" -p "$parola" "$prenume.$nume"
Code:IFS=' ' set -- $line fullname="$1 $2" prenum=$3 set -- `printf "%s\n" "$line" | tolower` nume=$1 grupa=$2


Reply With Quote
