Help with useradd script

Ok Im trying too make this shell script create users from my text file, I also want to type in a password for the new users. So thay can make a uniq one themself after first logon.

#!/bin/sh
# Sebastian schmidt
clear

echo    "*************************************************************"
echo    "Please choose from the following options; type the"
echo    "option number and hit the <Enter> key."
echo    "*************************************************************"
echo    ""
echo    "This script creates accounts for the people you have"
echo    "listed in the file 'users' and puts them in the group 'it'"
echo
echo    "  1) To Run this script"
echo    "  2) Exit"
echo
echo    "*************************************************************"
read option

id | grep root 2>/dev/null >/dev/null
if [ $? -eq 1 ]
then
clear
        echo "You need to be root before running this script."
        echo "Please restart this script as root and all will be fine."
exit
fi


if [ "$option" = "1" ]
then
## This is going to be future implementation of chosing password at creation
echo "Type password for the new users."
read pass
echo $pass

echo "Type in the path for the file (users)"
read users
        groupadd it 2>/dev/null >/dev/null
        for i in `sed 's/\(..\).*@\(..\).*/\1\2/' $users`
do
        useradd -g it -p $pass -s /bin/bash -m -d /home/it09$i it09$i 2>/dev/null >/dev/null
done

echo "Done!"

elif ["$option" = "2"]
then
        echo "exiting script"
exit
fi

This is how my text file looks like

sebastian@schmidt
sandra@fahlen
tomas@persson

This is what /etc/shadow looks like after running the script and what happens when I want to su to one of the new users.
I just dont understand why password is clear text in the shadow file.. As I think the problem lies there.

it09sesc:sebbe1:14402:0:99999:7:::
it09safa:sebbe1:14402:0:99999:7:::
it09tope:sebbe1:14402:0:99999:7:::


seb@webserver:/home$ su it09sesc
Password:
su: Authentication failure

Help wanted any hints on whats wrong here?

Have you read the man page for useradd?

  -p, --password PASSWORD
       The encrypted password, as returned by crypt(3).
       The default is to disable the account.

Amen to cfajohnson, he is absolutely correct. Still, there are some additional points to a script creating users I'd like to stress:

1) Your script has several prerequisites which should be tested. You test for the script being run as as root and quite correctly so. Still there should be tested a lot of more conditions: is your file readable, is it in the expected format (how does your script behave if a line looks "user @host" instead of "user@host"? What will happen if the host specified doesn't exist?), etc.. Robust scripting always takes into account the probable typo and other typical errors.

1a) Corollary: most of these tests are very generic and could be done in (external) functions, for instance the test if it is run under root privileges. Presumably you have a lot of other scripts also depending on being run under root. Why don't you write a function "Being_Root()", which just tests this condition and gives back TRUE or FALSE. Accordingly with some other necessary prerequisites.

2) In your script no effort is undertaken to find (and correct) error conditions. Suppose you let your script run and one of the user accounts does already exist. How does your script react in this case? Terminate? Write a log entry? Issue an error message on the screen? How should your script deal with such a problem?

3) Your script gives back no return value. This way it will not be possible to include it into future scripts, because you don't get back any information if the run was successful or not. Well-behaved programs return an error code upon termination (usually: 0=ok, 1-255 several error conditions, like: input file missing, prerequisites not met, user already existing, ... )

I hope this helps.

bakunin

Alright I have done som research and I found the solutions to the problem
regarding setting to a predefined password.
Added a line under the useradd loop.

read users
        groupadd it 2>/dev/null >/dev/null
        for i in `sed 's/\(..\).*@\(..\).*/\1\2/' $users`
do
        useradd -g it -s /bin/bash -m -d /home/it09$i it09$i 2>/dev/null >/dev/null
        echo it09$i:$pass | chpasswd
done

Now to those things you mentiond bakunin I will attend them now that I have solved the main problem. Thanks for those exelent tips you gave me. And thanks alot for all the help so far. This was a very nice first encounter with this forum.
Next up is to expand the options abit. So you can chose account name instead of it09. return value's will be dealt with and if a user exists some kind of event will acur.
Thanks agen for all the help so far. Im learning as I go along and so far its been alot of fun.