Shell script for user account Creation


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Shell script for user account Creation
# 1  
Old 05-25-2017
Lightbulb Shell script for user account Creation

Hi Folks,

I had a request to create the user request. Between, I just write a script a create, Update Geos, and update the password. My script as below:
The error message, what I am getting is all the users are updated with the same Goes value..

Code:
#!/bin/bash
for i in `cat users.txt`;do
for j in `cat geos.txt`;do 
useradd -s /bin/bash -m -d /home/$i -c "$j" -g mysql $i 
echo "Password" | passwd --stdin $i 
chage -d 0 $i 
done


Moderator's Comments:
Mod Comment Please use CODE tags correctly as required by forum rules!

Last edited by RudiC; 05-25-2017 at 03:19 AM.. Reason: Changed QUOTE to CODE tags.
# 2  
Old 05-25-2017
You might want to explain what you think your script is doing so we can compare that to what it is actually doing.

But, even before that, it would help if you would show us the entire script and any diagnostic messages produced when you run your code. (Having two for loops with two dos and only one done isn't a good start.)

Note also that:
Code:
for j in `cat geos.txt`

goes through your loop once for each field in geos.txt (not once for each line in geos.txt). I have no idea why you would want to invoke useradd, passwd, and chage for each field in geos.txt for each user in users.txt. It would seem that it would make more sense to invoke those utilities once per user with data from a full line of geos.txt that corresponds to that user.
# 3  
Old 05-25-2017
Quote:
Originally Posted by gsiva
Hi Folks,

I had a request to create the user request. Between, I just write a script a create, Update Geos, and update the password. My script as below:
The error message, what I am getting is all the users are updated with the same Goes value..
set -vx in your script so you can see what it is occurring. For each line in user.txt you are looping every line from geos.txt file.

Maybe something like this. Not tested.

Code:
#!/bin/bash
paste users.txt geos.txt | while IFS= read u g; do
    useradd -s /bin/bash -m -d /home/$u -c "$g" -g mysql $u
    echo "Password" | passwd --stdin $u
    chage -d 0 $u
done

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Create a shell script to gather user account information and displays the result to administrator

I want to create a shell script to gather user account information and displays the result to administrator. I have created a script but its showing all the information when i search for username like: amit@mx:~$ ./uinfo.sh amit Username : amit User Info ... (2 Replies)
Discussion started by: amit1986
2 Replies

2. Windows & DOS: Issues & Discussions

Problems With User Creation Script

Hello everyone, I've been attempting to make a program which creates user accounts from a file which contains the usernames required. It also checks if the directory of the username exists in the C:\Users directory and then is going to give the option to delete the directory, or rename it, this... (1 Reply)
Discussion started by: charlieabee
1 Replies

3. Shell Programming and Scripting

Bash shell script for user creation in solaris

Hi All, I am new to shell scripting and have a task which need to be completed ASAP. I have searched all the forum and couln't find excat script which could run on solaris.can someone give me the fully working script for below. Bash shell script to create user account with paraments as... (1 Reply)
Discussion started by: sintilash
1 Replies

4. Shell Programming and Scripting

User creation script

Hi Gems.. I am working out on project of creating a mass user on 100 server. Please help me with script where i can create an user id of new 80 user using shell script Thanks in advance. Indrajit Bhagat (1 Reply)
Discussion started by: indrajit_renu
1 Replies

5. UNIX for Dummies Questions & Answers

User account with no login shell

Hi All, I was reading a tutorial for Installing Tomcat on Linux machine. (http://www.puschitz.com/InstallingTomcat.html) Here the author had mentioned that: For security reasons I created a user account with no login shell for running the Tomcat server. My question is: 1. What is a User... (6 Replies)
Discussion started by: jw_amp
6 Replies

6. Shell Programming and Scripting

Create new user account and password in shell script

I am trying to create a shell script that will: check if a specific user already exists if not, create a specific group and create the user in that group assign a password to that user, where the password is passed in as a parameter to the script The problem that I need help with is 3 on... (4 Replies)
Discussion started by: killuane
4 Replies

7. Shell Programming and Scripting

Help in Shell scripting to modify the User Creation script in oracle database.

Hi, I have several users to create on my test Oracle database taking the scripts from the Production Oracle database. I have a separate text file where I have user-id and passwords maintained. I need help in writing a shell script to go thru the user creation scripts and replace VALUES... (1 Reply)
Discussion started by: rparavastu
1 Replies

8. UNIX for Dummies Questions & Answers

user account creation date

hi, i tried searching the forum for a thread about this, but came up empty handed. is there a way to pull a list of all user accounts, with the associated creation date? thanks in advance! (2 Replies)
Discussion started by: lilweezy
2 Replies

9. Forum Support Area for Unregistered Users & Account Problems

Account creation trouble

I created an account a while back, but never received any confirmation, so I could never get the full access... :( I logged back in today, but I'd forgotten what I'd used for username... anyway, I entered my email address and it said that I would receive my login information, which I... (2 Replies)
Discussion started by: seaghan
2 Replies

10. Shell Programming and Scripting

user creation using shell script for JSP

hello friends, I have problem. We want to create user from jsp(browser based) on our linux server. How we can do that ? or How do we create a user with shell programming by taking arguments and checking with the existing users and if the user exist it should display the message the user exists... (1 Reply)
Discussion started by: jarkvarma
1 Replies
Login or Register to Ask a Question