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..

#!/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 

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 do s and only one done isn't a good start.)

Note also that:

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.

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.

#!/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