Sponsored Content
Full Discussion: Help with useradd script
Top Forums Shell Programming and Scripting Help with useradd script Post 302323363 by chipmunken on Sunday 7th of June 2009 06:13:35 AM
Old 06-07-2009
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.

Code:
#!/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
Code:
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.
Code:
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?
 

9 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

useradd script

I have a txt file with many users and I need to add them and create random passwords. Does any one have a script in pearl possible? (3 Replies)
Discussion started by: macdonto
3 Replies

2. Shell Programming and Scripting

useradd -c in a script????

Here's my box info: ROOT@fcivra: uname -a SunOS fcivra 5.6 Generic_105181-26 sun4m sparc SUNW,SPARCstation-5 I am creating a script called adduser, that will incorporate the useradd command. Here is what it looks like: #!/bin/sh echo "Enter the person's VZID (lower case): \c" read VZID... (2 Replies)
Discussion started by: cdunavent
2 Replies

3. Shell Programming and Scripting

useradd

Gurus, I need to add a user to all the machines. I need a script to do this. I did one but it does not allow me to su to root within a ssh session i open. It exists saying su: Sorry. Please let me know how i can do it. I do not have the freedom of using sudo either. Regards (4 Replies)
Discussion started by: earlysame55
4 Replies

4. UNIX for Advanced & Expert Users

useradd?

Hi Experts, when using useradd command, what are the necessary options/arguments to be included? Please advice. (4 Replies)
Discussion started by: etcpasswd
4 Replies

5. Shell Programming and Scripting

trouble making a useradd script

i'm new to scripting in unix and am trying to make a script to add a user and an encrypted password for them. this is what i have and it isn't giving me any errors, but when i try to login with the new user, the password doesn't work. i'm hoping someone can point me in the right direction ... (1 Reply)
Discussion started by: patt4179
1 Replies

6. Solaris

useradd

if useradd command is deleted in solaris how do we add user (3 Replies)
Discussion started by: vivek_ng
3 Replies

7. Shell Programming and Scripting

need script for smbldap-useradd/setquota/ldapadd

Hello guys, I am trying to add users to samba/ldap system, set their quota, set them a common password and add auto_home records for the new users User list file is in below format Firstname Lastname Username Command I run to add user is smbldap-useradd -a -m -N $Firstname -S... (0 Replies)
Discussion started by: upengan78
0 Replies

8. Solaris

useradd

I want to creat a 27 logins in solaris.Can anyone tell me how to write a script for that so that i create at a time for all 27 people. Thanks to guide me. (6 Replies)
Discussion started by: kkalyan
6 Replies

9. Shell Programming and Scripting

Useradd script

Trying to create a bash script that will read the /etc/passwd file for existing UID's before adding a new user and also does an incremental by allocating the next available UID.And also add the user to the correct group.Please help I am a newbie in scripting. (2 Replies)
Discussion started by: tshepang
2 Replies
escape(1)							Mail Avenger 0.8.3							 escape(1)

NAME
escape - escape shell special characters in a string SYNOPSIS
escape string DESCRIPTION
escape prepends a "" character to all shell special characters in string, making it safe to compose a shell command with the result. EXAMPLES
The following is a contrived example showing how one can unintentionally end up executing the contents of a string: $ var='; echo gotcha!' $ eval echo hi $var hi gotcha! $ Using escape, one can avoid executing the contents of $var: $ eval echo hi `escape "$var"` hi ; echo gotcha! $ A less contrived example is passing arguments to Mail Avenger bodytest commands containing possibly unsafe environment variables. For example, you might write a hypothetical reject_bcc script to reject mail not explicitly addressed to the recipient: #!/bin/sh formail -x to -x cc -x resent-to -x resent-cc | fgrep "$1" > /dev/null && exit 0 echo "<$1>.. address does not accept blind carbon copies" exit 100 To invoke this script, passing it the recipient address as an argument, you would need to put the following in your Mail Avenger rcpt script: bodytest reject_bcc `escape "$RECIPIENT"` SEE ALSO
avenger(1), The Mail Avenger home page: <http://www.mailavenger.org/>. BUGS
escape is designed for the Bourne shell, which is what Mail Avenger scripts use. escape might or might not work with other shells. AUTHOR
David Mazieres Mail Avenger 0.8.3 2012-04-05 escape(1)
All times are GMT -4. The time now is 10:23 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy