Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- #EMPIEZA
- # Limpio la pantalla
- clear
- # Imprimo el cartel en pantalla
- echo -n "***************************"
- echo -n "SCRIPT PARA CREAR USUARIOS"
- echo -n "***************************"
- # Me fijo si mi id es 0 (correspondiente a root) de lo contrario salgo
- # ya que necesito permisos de root para crear usuarios nuevos
- if [ "`id -u`" != 0 ] ; then
- echo -e "\n"
- echo "Necesito tener permisos de root para ejecutar mis tareas,"
- exit 1
- fi
- #mioooooooooooooooooooooooooooooooooooooooooooooooooooooo
- while read nombre home grupo shell
- do
- #if [ $nombre == "rdd" ];then
- #nombre=a
- #home=a
- #grupo=1
- #shell=a
- #fi
- if [ $grupo == "/bin/bash" ] ;then
- grupo=1001
- fi
- if [ $shell == "" ];then
- shell=$(/bin/bash)
- fi
- if [ $home -eq * ];then
- nombre=$(/home/$nombre)
- fi
- #if [ var1 != "/home/$nombre" ];then
- #var1=$(cat usuariosSystem | grep /home/$nombre | cut -f 2 -d " ")
- #fi
- if [ "$home" != "/home/$nombre" ];then
- home=$(/home/$nombre)
- fi
- if [ "$shell" != "/bin/bash" ] ;then
- shell=$(/bin/bash)
- fi
- # Si el nombre del usuario está vacío entonces salgo del script
- if [ "$nombre" == "" ] ; then
- clear
- echo -e "\n"
- echo "El nombre no puede estar vacío"
- echo -e "\n"
- exit 1
- fi
- # Si no ingreso ningún directorio home dejo el que viene por defecto
- if [ "$home" == "" ] ; then
- home="/home/$nombre"
- fi
- # Ingreso el grupo 1000 que generalmente es el de usuarios comunes por defecto
- #if [ "$grupo" == "" ] ; then
- #grupo=1000
- #fi
- # Si no ingreso ningún shell como por ejemplo un menu, dejo con el shell por defecto
- if [ "$shell" == "" ] ; then
- shell="/bin/bash"
- fi
- # Limpio la pantalla
- clear
- # Hago un resumen de los datos ingresados
- echo "Los datos ingresados son los siguientes:"
- echo "****************************************"
- echo -e "\n"
- echo "Nombre del usuario: $nombre"
- echo "Directorio home: $home"
- echo "Grupo del usuario: $grupo"
- echo "Shell por defecto : $shell"
- # Creo el usuario con las variables
- useradd -d /home/$nombre -g $grupo -m -s $shell $nombre
- # Si hay un error salgo del script
- if [ "$?" != 0 ] ; then
- echo -e "\n"
- echo "Ha ocurrido un error, asegurese de que los datos ingresados son correctos."
- exit 1
- fi
- # Por último pido la contraseña
- #echo -e "\n"
- #echo "Ingrese una contraseña para $nombre"
- #passwd $nombre
- # Si la contraseña no dio ningún error y llegamos a este paso el usuario ya esta creado
- echo -e "\n"
- echo "El usuario fue creado satisfactoriamente"
- #nombre home grupo shell
- done < usuariosSystem
- #No hemos encontrado la forma de mostrar el usuario rdd y hemos utilizado una opción mas rudimentaria PERO EFECTIVA :) (Fran e Ivan).
- useradd -d /home/rdd -g 1002 -m -s /bin/bash rdd
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement