I'm trying to create multiple users from a csv file from a bash shell script. My csv looks like this
Codigo,Apellido,Nombre,Carrera,Facultad,Rol
10001,Accorti,Paolo,COM,FACED,Profesor
10002,Afonso,Pedro,ICI,FIA,Estudiante
.
.
.
I have the following code
#!/bin/bash
while IFS=, read -r Codigo Apellido Nombre Carrera Facultad Rol;
do
password="Pass123"
sudo useradd -c "${Codigo} ${Apellido}" -d "/home/$codigo" -s /bin/bash -p "${password}"
done < Usuarios.csv
When I run the code, I don't have any error but my terminal shows options for useradd and my accounts have not been created. This is my first time programming in bash shell, I'm not sure what I'm doing wrong.
Taken from the man pages for useradd:
-p, --password PASSWORD
The encrypted password, as returned by crypt(3). The default is to
disable the password.
Note: This option is not recommended because the password (or
encrypted password) will be visible by users listing the processes.
You should make sure the password respects the system's password
policy.
The password when passed with -p will need to be encrypted and cannot be plain text. The alternative will be to use passwd
Another possibility would be to user newusers, although this is distribution specific.
I think your command for "useradd" is wrong.
#!/bin/bash
while IFS=, read -r Codigo Apellido Nombre Carrera Facultad Rol;
do
password="Pass123"
useradd -c "${Codigo} ${Apellido}" -m -p ${password} -s /bin/bash ${Codigo}
done < Usuarios.csv
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.