Jump to content

Shell script problem


chipmunken

Recommended Posts

Ok Im trying too make this shell script create users from my text file, I also want to type in a password that will be set to the users.

 

#!/bin/sh
# Sebastian schmidt
clear
        echo "This script creates accounts for the people you have listed in the file (users) and puts them in the group it."
        echo ""
        echo "given and surname must be seperated with ( in the file (users)."
        echo "If you want to execute the script now type (yes) and press enter, else type exit and press enter."



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

read svar

if [ "$svar" = "yes" ]
then
echo "Type password for the new users."
read pass

echo "Type in the path for the file (users)"
#echo $pass
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 ["$svar" = "exit"]
then
        echo "exiting script"
exit
fi

 

This is how my textfile looks like

sebastian@schmidt
sandra@fahlen
tomas@persson

 

All works fine when it comes to createing the users and home catalogs. The problem is the password wont stick.. I dont know whats wrong. When I switch to a normal user and try to su to one of the created users it asks me for a password and then it says

seb@webserver:/home$ su it09sesc

Password:

su: Authentication failure

Help wanted :D

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.