#!/bin/bash
opcion="9"
while [[ $opcion != "0" ]]
do
clear
echo "..:GESTION DE USUARIO:.."
echo ""
echo "1) Agregar un usuario "
echo "2) Eliminar un usuario"
echo "3) Modificar un usuario "
echo "4) Visualizar todos los usuarios "
echo "5) Bloquear usuario"
echo "6) Desbloquear usuario"
echo "7) Asignar interprete de comandos"
echo "0) Salir"
echo ""
echo -n "ELIJA UNA OPCION:"
read opcion
#######################################################################################################
case $opcion in
##############################################################################################################
1)
echo "..:CREAR USUARIO:.."
echo ""
echo -n "Ingrese el nombre:"
read nom
aux=$( cat /etc/passwd | grep $nom | cut -d ":" -f1 )
if [[ -z $aux ]]
then
echo "Ingrese el nombre del grupo"
read grp
if [ -z $grp ]
then
echo "ERROR! no se ha especificado grupo"
else
aux=$( cat /etc/group | grep -w $grp | cut -d ":" -f1 )
if [ -z $aux ]
then
echo "ERROR!!! el grupo no existe"
sleep 1
else
useradd -G $gro $nom
read -s pass |
echo "$pass"|passwd --stdin $nom
echo "Usuario $nom creado"
sleep 1
fi
fi
else
echo "ERROR!!! el usuario ya existe"
sleep 1
break
fi
sleep 1
;;
###################################################################################################
2)
clear
echo "..:ELIMINAR USUARIO:.."
echo ""
echo -n "Nombre de usuario a eliminar:"
read nom2
aux2=$( cat /etc/passwd | grep $nom2 | cut -d ":" -f1 )
if [[ -z $aux2 ]]
then
echo "ERROR!!! el usuario no existe"
break
else
echo "Desea tambien borrar los datos de $nom2?(s/n)"
read dat
if [[ $dat == 's' ]]
then
userdel -r $nom2
else
userdel $nom2
fi
fi
echo "Usuario $nom2 BORRADO"
sleep 2;;
#######################################################################################################
3)
./mod_user.sh
;;
#############################################################################################################
4) echo ""
echo "precione ENTER para salir"
echo ""
echo "NOMBRE DE USUARIO:CONTRASEÑA ENCRIPTADA:UID:GID:COMENTARIO:HOME DE TRABAJO:INTERPRETE"
cat /etc/passwd;
sleep 2
;;
###########################################################################################################
5) clear
echo "..:BLOQUEAR USUARIO:.."
echo
y=0
while [[ $y == "0" ]]
do
echo "Ingrese el nombre a bloquear:"
read nom3
aux3=$( cat /etc/passwd | grep $nom3 | cut -d ":" -f1 )
if [ -z $aux3 ]
then
echo "Error, el usuario no existe"
y=0
else
y=1
usermod -L $nom3
fi
done
;;
###########################################################################################################
6) clear
echo "****DESBLOQUEAR USUARIO****"
echo
y=0
while [[ $y == "0" ]]
do
echo "Ingrese el nombre a desbloquear:"
read nom3
aux3=$( cat /etc/passwd | grep $nom3 | cut -d ":" -f1 )
if [ -z $aux3 ]
then
echo "Error, el usuario no existe"
y=0
else
y=1
usermod -U $nom3
fi
done
;;
############################################################################################################
7) clear
echo "..:ASIGNAR INTERPRETE DE COMANDOS:.."
echo -n "Ingrese el nombre del usuario:"
read $user
aux3=$( cat /etc/passwd | grep $nom3 | cut -d ":" -f1 )
if [ -z $aux3 ]
then
echo "el usuario no existe"
else
echo "Seleccione el interprete de comandos"
echo "1) /bin/bash"
echo "2) /bin/false"
echo "Elija uno:"
read bin
if [[ $bin == "1" ]]
then
usermod -s /bin/bash $user
elif [[ $bun == "2" ]]
then
usermod -s /bin/false
else
echo "opcion incorrecta!!"
fi
fi
;;
############################################################################################################
0) echo "FIN"
sleep 2
break
;;
############################################################################################################
*) echo "ERROR!!! opcion incorrecta, vuelva a intentar"
sleep 2
esac
done
opcion="9"
while [[ $opcion != "0" ]]
do
clear
echo "..:GESTION DE USUARIO:.."
echo ""
echo "1) Agregar un usuario "
echo "2) Eliminar un usuario"
echo "3) Modificar un usuario "
echo "4) Visualizar todos los usuarios "
echo "5) Bloquear usuario"
echo "6) Desbloquear usuario"
echo "7) Asignar interprete de comandos"
echo "0) Salir"
echo ""
echo -n "ELIJA UNA OPCION:"
read opcion
#######################################################################################################
case $opcion in
##############################################################################################################
1)
echo "..:CREAR USUARIO:.."
echo ""
echo -n "Ingrese el nombre:"
read nom
aux=$( cat /etc/passwd | grep $nom | cut -d ":" -f1 )
if [[ -z $aux ]]
then
echo "Ingrese el nombre del grupo"
read grp
if [ -z $grp ]
then
echo "ERROR! no se ha especificado grupo"
else
aux=$( cat /etc/group | grep -w $grp | cut -d ":" -f1 )
if [ -z $aux ]
then
echo "ERROR!!! el grupo no existe"
sleep 1
else
useradd -G $gro $nom
read -s pass |
echo "$pass"|passwd --stdin $nom
echo "Usuario $nom creado"
sleep 1
fi
fi
else
echo "ERROR!!! el usuario ya existe"
sleep 1
break
fi
sleep 1
;;
###################################################################################################
2)
clear
echo "..:ELIMINAR USUARIO:.."
echo ""
echo -n "Nombre de usuario a eliminar:"
read nom2
aux2=$( cat /etc/passwd | grep $nom2 | cut -d ":" -f1 )
if [[ -z $aux2 ]]
then
echo "ERROR!!! el usuario no existe"
break
else
echo "Desea tambien borrar los datos de $nom2?(s/n)"
read dat
if [[ $dat == 's' ]]
then
userdel -r $nom2
else
userdel $nom2
fi
fi
echo "Usuario $nom2 BORRADO"
sleep 2;;
#######################################################################################################
3)
./mod_user.sh
;;
#############################################################################################################
4) echo ""
echo "precione ENTER para salir"
echo ""
echo "NOMBRE DE USUARIO:CONTRASEÑA ENCRIPTADA:UID:GID:COMENTARIO:HOME DE TRABAJO:INTERPRETE"
cat /etc/passwd;
sleep 2
;;
###########################################################################################################
5) clear
echo "..:BLOQUEAR USUARIO:.."
echo
y=0
while [[ $y == "0" ]]
do
echo "Ingrese el nombre a bloquear:"
read nom3
aux3=$( cat /etc/passwd | grep $nom3 | cut -d ":" -f1 )
if [ -z $aux3 ]
then
echo "Error, el usuario no existe"
y=0
else
y=1
usermod -L $nom3
fi
done
;;
###########################################################################################################
6) clear
echo "****DESBLOQUEAR USUARIO****"
echo
y=0
while [[ $y == "0" ]]
do
echo "Ingrese el nombre a desbloquear:"
read nom3
aux3=$( cat /etc/passwd | grep $nom3 | cut -d ":" -f1 )
if [ -z $aux3 ]
then
echo "Error, el usuario no existe"
y=0
else
y=1
usermod -U $nom3
fi
done
;;
############################################################################################################
7) clear
echo "..:ASIGNAR INTERPRETE DE COMANDOS:.."
echo -n "Ingrese el nombre del usuario:"
read $user
aux3=$( cat /etc/passwd | grep $nom3 | cut -d ":" -f1 )
if [ -z $aux3 ]
then
echo "el usuario no existe"
else
echo "Seleccione el interprete de comandos"
echo "1) /bin/bash"
echo "2) /bin/false"
echo "Elija uno:"
read bin
if [[ $bin == "1" ]]
then
usermod -s /bin/bash $user
elif [[ $bun == "2" ]]
then
usermod -s /bin/false
else
echo "opcion incorrecta!!"
fi
fi
;;
############################################################################################################
0) echo "FIN"
sleep 2
break
;;
############################################################################################################
*) echo "ERROR!!! opcion incorrecta, vuelva a intentar"
sleep 2
esac
done