Advertisement
Guest User

Untitled

a guest
Feb 13th, 2018
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.69 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. #EMPIEZA
  4.  
  5. # Limpio la pantalla
  6. clear
  7.  
  8. # Imprimo el cartel en pantalla
  9. echo -n "***************************"
  10. echo -n "SCRIPT PARA CREAR USUARIOS"
  11. echo -n "***************************"
  12.  
  13.  
  14. # Me fijo si mi id es 0 (correspondiente a root) de lo contrario salgo
  15. # ya que necesito permisos de root para crear usuarios nuevos
  16. if [ "`id -u`" != 0 ] ; then
  17. echo -e "\n"
  18. echo "Necesito tener permisos de root para ejecutar mis tareas,"
  19. exit 1
  20. fi
  21.  
  22. #mioooooooooooooooooooooooooooooooooooooooooooooooooooooo
  23.  
  24.  
  25.  
  26.  
  27. while read nombre home grupo shell
  28. do
  29.  
  30. #if [ $nombre == "rdd" ];then
  31. #nombre=a
  32. #home=a
  33. #grupo=1
  34. #shell=a
  35. #fi
  36.  
  37. if [ $grupo == "/bin/bash" ] ;then
  38. grupo=1001
  39. fi
  40.  
  41. if [ $shell == "" ];then
  42. shell=$(/bin/bash)
  43. fi
  44.  
  45. if [ $home -eq * ];then
  46. nombre=$(/home/$nombre)
  47. fi
  48.  
  49. #if [ var1 != "/home/$nombre" ];then
  50. #var1=$(cat usuariosSystem | grep /home/$nombre | cut -f 2 -d " ")
  51. #fi
  52.  
  53. if [ "$home" != "/home/$nombre" ];then
  54. home=$(/home/$nombre)
  55. fi
  56.  
  57. if [ "$shell" != "/bin/bash" ] ;then
  58. shell=$(/bin/bash)
  59. fi
  60.  
  61.  
  62. # Si el nombre del usuario está vacío entonces salgo del script
  63. if [ "$nombre" == "" ] ; then
  64. clear
  65. echo -e "\n"
  66. echo "El nombre no puede estar vacío"
  67. echo -e "\n"
  68. exit 1
  69. fi
  70. # Si no ingreso ningún directorio home dejo el que viene por defecto
  71. if [ "$home" == "" ] ; then
  72. home="/home/$nombre"
  73. fi
  74.  
  75. # Ingreso el grupo 1000 que generalmente es el de usuarios comunes por defecto
  76. #if [ "$grupo" == "" ] ; then
  77. #grupo=1000
  78. #fi
  79.  
  80. # Si no ingreso ningún shell como por ejemplo un menu, dejo con el shell por defecto
  81. if [ "$shell" == "" ] ; then
  82. shell="/bin/bash"
  83. fi
  84.  
  85. # Limpio la pantalla
  86. clear
  87.  
  88. # Hago un resumen de los datos ingresados
  89. echo "Los datos ingresados son los siguientes:"
  90. echo "****************************************"
  91. echo -e "\n"
  92. echo "Nombre del usuario: $nombre"
  93. echo "Directorio home: $home"
  94. echo "Grupo del usuario: $grupo"
  95. echo "Shell por defecto : $shell"
  96.  
  97. # Creo el usuario con las variables
  98. useradd -d /home/$nombre -g $grupo -m -s $shell $nombre
  99. # Si hay un error salgo del script
  100. if [ "$?" != 0 ] ; then
  101. echo -e "\n"
  102. echo "Ha ocurrido un error, asegurese de que los datos ingresados son correctos."
  103. exit 1
  104. fi
  105.  
  106. # Por último pido la contraseña
  107. #echo -e "\n"
  108. #echo "Ingrese una contraseña para $nombre"
  109. #passwd $nombre
  110.  
  111. # Si la contraseña no dio ningún error y llegamos a este paso el usuario ya esta creado
  112. echo -e "\n"
  113. echo "El usuario fue creado satisfactoriamente"
  114.  
  115.  
  116.  
  117. #nombre home grupo shell
  118.  
  119. done < usuariosSystem
  120. #No hemos encontrado la forma de mostrar el usuario rdd y hemos utilizado una opción mas rudimentaria PERO EFECTIVA :) (Fran e Ivan).
  121. useradd -d /home/rdd -g 1002 -m -s /bin/bash rdd
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement