Hola a todos.

Hace tiempo que busco la manera de solucionar esto y no lo puedo hacer.

Tengo un archivo de datos en modo txt sacado del archivo passwd, al que le he suprimido todo menos los siguientes datos:

usuario:nombre:grupo:home

Por ejemplo:

gSanabria:Gustavo Sanabria:Estadistica:/home/estadistica/gSanabria

 

Con un script que encontre en Internet para agregar usuarios desde un archivo me funciona pero siempre y cuando no use el “nombre” ya que ahí falla el script, es decir, no me trae correctamente el nombre completo del usuario. El script en cuestion es:

 

#script to add many users .

#here you will have to create a file called users.dat in /root dir.

#the format of the file should be as below

#USER:GROUPNAME:HOMEDIRECTORY:SHELL

#the script will take the parameters as input and configure the user.

#the passwd of the user will also be configured thru the script.

 

#you can add as many users as you want via this script by editing the /tmp/users.dat file.

#

#script by Suhas Oka...........

for i in `cat /root/users.dat`

do

USER=`echo $i | awk -F":" '{print $1}'`

GROUP=`echo $i | awk -F":" '{print $2}'`

DIR=`echo $i | awk -F":" '{print $3}'`

SHELL=`echo $i | awk -F":" '{print $4}'`

/usr/sbin/useradd -g $GROUP -d $DIR -m -s $SHELL $USER

done

#script to add single user.....

 

Yo lo modifique para incluir el nombre de esta forma:

USER=`echo $i | awk -F":" '{print $1}'`

NAMEUSU=`echo $i | awk -F":" '{print $2}'`

GROUP=`echo $i | awk -F":" '{print $3}'`

DIR=`echo $i | awk -F":" '{print $4}'`

SHELL=`echo $i | awk -F":" '{print $5}'`

/usr/sbin/useradd -g $GROUP -d $DIR –c $NAMEUSU -m -s $SHELL $USER

done

 

Pero no funciona porque no reconoce el espacio en blanco del nombre completo del usuario y me trunca y desacomoda el resto de los datos.

Alguien tiene alguna sugerencia de cómo lo puedo hacer?

Saludos cordiales,

Responder a