-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate_user.sh
More file actions
54 lines (44 loc) · 938 Bytes
/
create_user.sh
File metadata and controls
54 lines (44 loc) · 938 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
!/bin/bash
function crearusuario(){
if grep -q "$3" /etc/group
then
useradd -mg "$3" "$1"
echo -e "$1:$2" | chpasswd
else
addgroup "$3"
useradd -mg "$3" "$1"
echo -e "$1:$2" | chpasswd
fi
}
#----------------------------PROGRAMA--------------------------------
clear
if [[ $EUID -ne 0 ]]
then
echo -e "El usuario NO es root, por lo que no se permite ejecutar el script"
exit 1
fi
echo -e "Introduzca la ubicación del fichero:"
A=0
while [ $A -eq 0 ];
do
read fichero
if [[ -s $fichero ]]
then
A=1
else
echo "ERROR: el fichero no existe o está vacío."
echo "Introduzca de nuevo el nombre y ruta del fichero:\n"
fi
done
while read -a line
do
encabezado=$(echo "${line[0]}" |grep "#")
if [ -z $encabezado ]
then
user="${line[0]}"
pass="${line[1]}"
group="${line[2]}"
active="${line[3]}"
crearusuario $user $pass $group $active
fi
done < $fichero