I'm trying to add users to the system from a file. The file looks exactly like this:
[email protected] password 1
[email protected] baddpassword 2
The numbers are their IDs. Its coming from a mysql db and I need to do something with those variables too so I need 4 variables. The USER, PASS, FIRSTID (being 1) and LASTID (being the last ID of the mysql dump in this case, 2. This is considering more than 2 entries at a time)
So far what I have is this:
for USER in $(awk -F@ 'NR>1 {print $1}' /root/users_w_pass)
do
for PASS in $(awk 'NR>1 {print $2}' /root/users_w_pass)
do
useradd $USER -d /home/$USER -m
echo "$USER:$PASS" | chpasswd
...
done
done
When running this, the password does not get added to the corresponding user and I have no idea on how I am supposed to do that since I thought it would work but I can see how it doesn't. It seems to loop the password. Also I am creating files and assigning ACLs for each, so running newusers
on a file won't work here, especially that there is a third column as well.