-
Notifications
You must be signed in to change notification settings - Fork 1
/
ej13.sh
executable file
·32 lines (27 loc) · 974 Bytes
/
ej13.sh
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
#! /bin/bash
echo "Extraer archivos de un usuario específico"
if [ $# -ne 1 ]
then
echo "Uso: $0 <nombre de usuario>"
exit 1
fi
echo "Ingresar la dirección del archivo de cinta"
read cinta
usuario="$1"
directorio_usuario="/tmp/copia$usuario"
if ! test -d "$directorio_usuario" ; then
mkdir -p "$directorio_usuario"
fi
if grep -q "$usuario" "/etc/passwd"
then
#-tv muestra los archivos en formato ls -l
#awk muestra solo las lineas con el propietario "usuario"
#cpio usa directorios relativos, para copiar directamente sobre el directorio activo (directorio_usuario)
#lo mismo se hace con el cpio -t, para que los liste como archivos relativos
cpio -idumF "$cinta" -D "$directorio_usuario" --no-absolute-filenames --quiet $(cpio -tv < "$cinta" --no-absolute-filenames --quiet | awk '{ if($3 == "'$usuario'") print $0}')
echo "Los archivos se han copiado exitosamente"
else
echo "No se ha encontrado el usuario $usuario"
sleep 3
exit 1
fi