Revisión 520
Añadido por Alfonso Pastor hace más de 10 años
scripts/ldap/generacion_listados_inicio_curso_pdf.sh | ||
---|---|---|
#!/bin/bash
|
||
|
||
#Version 2.4
|
||
#Fecha 3/10/2013
|
||
#Version 2.5
|
||
#Fecha 21/10/2014
|
||
#Autores: Alfonso Pastor. IES Virgen de Guadalupe-Cáceres.
|
||
# José María Sánchez García. IES Parque de Monfragüe.
|
||
# impresión de cada grupo de alumnos en una hoja distinta, evitando que queden cortadas entre pagina y pagina.
|
||
... | ... | |
# Generación automática de la fecha del curso en función de la fecha de ejecución del script.
|
||
#Cometido: Extrae datos del fichero Alumnos.xml generado por Rayuela, despues de haberlos importado en LDAP.
|
||
# Construye un fichero html y, si esta instalado wkhtmltopdf, un PDF de grupos y alumnos, con los datos de login y contraseña.
|
||
|
||
#Modificaciones:
|
||
# 2.5: cambiado el usuario "admin" por el usuario "replica", para evitar que se pida contraseña.
|
||
# incluida generación de listado de profesores.
|
||
#AVISO: por las herramientas que utiliza este script no debe ejecutarse en el servidor ldap, mejor ejecutarlo en un
|
||
# workstation normal y corriente que tenga acceso a ldap.
|
||
|
||
... | ... | |
exit
|
||
fi
|
||
|
||
xmlstarlet sel -t -m "/profesorado-centro/profesor" -v "concat(dni,':',nombre,' ',primer-apellido,' ',segundo-apellido)" -n $3 > /tmp/profes.txt
|
||
xmlstarlet sel -t -m "/profesorado-centro/profesor" -v "concat(dni,':',nombre,' ',primer-apellido,' ',segundo-apellido,':',datos-usuario-rayuela/login)" -n $3 > /tmp/profes.txt
|
||
codificacion=$(file -i /tmp/profes.txt | cut -d"=" -f2)
|
||
#Si no estan en utf-8 los convertimos a dicho formato
|
||
if [ "$codificacion" != "utf-8" ]
|
||
... | ... | |
fi
|
||
|
||
|
||
echo -n "Contraseña de administrador de la BBDD ldap: "
|
||
read pwd
|
||
#echo -n "Contraseña de administrador de la BBDD ldap: "
|
||
#read pwd
|
||
pwd="replica"
|
||
user="cn=replica,dc=instituto,dc=extremadura,dc=es"
|
||
|
||
consulta=$(ldapsearch -w $pwd -D "cn=admin,ou=People,dc=instituto,dc=extremadura,dc=es" -xLLL -h ldap -b "ou=People,dc=instituto,dc=extremadura,dc=es" "cn=admin")
|
||
consulta=$(ldapsearch -w $pwd -D $user -xLLL -h ldap -b "ou=People,dc=instituto,dc=extremadura,dc=es" "cn=admin")
|
||
if [ -z "$consulta" ]
|
||
then
|
||
echo "La contraseña es incorrecta o bien no hay conexión con ldap"
|
||
... | ... | |
|
||
echo "Empiezo del proceso. Se ordenará cada grupo por $ORDENAR_POR"
|
||
|
||
destino=$4
|
||
destinobase=$(basename "$destino" .html)
|
||
destinoprofes="${destinobase}-profes.html"
|
||
destinopdf="${destinobase}.pdf"
|
||
|
||
#Generamos el html en utf8
|
||
echo "<html><head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\"/><style>table {page-break-after:always;}</style></head><body><div style='width: 800px'>" > $4
|
||
#Generacion de listado de profesores
|
||
|
||
echo "<html><head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\"/><style>table {page-break-after:always;}</style></head><body><div style='width: 800px'>" > $destinoprofes
|
||
|
||
echo "<h1><p align="center">Listados claves alumnos curso $curso </p></h1>" >> $4
|
||
echo "<h1><p align="center">Listados credenciales profesores curso $curso </p></h1>" >> $destinoprofes
|
||
|
||
echo "" >> $4
|
||
echo "<table width='70%' border=1>" >> $destinoprofes
|
||
echo "<tr bgcolor='#CCCCCC'>" >> $destinoprofes
|
||
echo "<td width='20%'>Login</td>" >> $destinoprofes
|
||
echo "<td width='60%'>Nombre</td>" >> $destinoprofes
|
||
echo "<td width='20%'>Password</td>" >> $destinoprofes
|
||
echo "</tr" >> $destinoprofes
|
||
|
||
while read lineaprofe
|
||
do
|
||
|
||
login=$(echo $lineaprofe | cut -d: -f1)
|
||
nombre=$(echo $lineaprofe | cut -d: -f2)
|
||
passwd=$(echo $lineaprofe | cut -d: -f3)
|
||
echo "<tr>" >> $destinoprofes
|
||
echo "<td>$login</td><td>$nombre</td><td>$passwd</td>" >> $destinoprofes
|
||
echo "</tr>" >> $destinoprofes
|
||
|
||
done < "/tmp/profes2.txt"
|
||
|
||
echo "</table>" >> $destinoprofes
|
||
echo "</div></body></html>" >> $destinoprofes
|
||
|
||
|
||
#Generacion del listado de alumnos.
|
||
|
||
echo "<html><head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\"/><style>table {page-break-after:always;}</style></head><body><div style='width: 800px'>" > $destino
|
||
echo "<h1><p align="center">Listados claves alumnos curso $curso </p></h1>" >> $destino
|
||
|
||
echo "" >> $destino
|
||
echo "" > /tmp/alumtemp.txt
|
||
while read lineagrupo
|
||
do
|
||
... | ... | |
nombre_curso=$(echo $lineagrupo | cut -d: -f3)
|
||
nombre_tutor=$(grep "^$tutor:" /tmp/profes2.txt | cut -d: -f2)
|
||
|
||
echo "<table width='100%' border=1>" >> $4
|
||
echo "<tr bgcolor='#CCCCCC'>" >> $4
|
||
echo "<td colspan='2' width='50%'>Grupo: $grupo - $nombre_curso</td>" >> $4
|
||
echo "<td colspan='2'>Tutor: $tutor - $nombre_tutor</td>" >> $4
|
||
echo "</tr" >> $4
|
||
echo "<table width='100%' border=1>" >> $destino
|
||
echo "<tr bgcolor='#CCCCCC'>" >> $destino
|
||
echo "<td colspan='2' width='50%'>Grupo: $grupo - $nombre_curso</td>" >> $destino
|
||
echo "<td colspan='2'>Tutor: $tutor - $nombre_tutor</td>" >> $destino
|
||
echo "</tr" >> $destino
|
||
|
||
case "$ORDENAR_POR" in
|
||
"nie") grep "^$grupo:" /tmp/alumnos2.txt | sort -k1 -t':' >> /tmp/alumtemp.txt
|
||
... | ... | |
;;
|
||
esac
|
||
|
||
echo "<tr bgcolor='#F0F8FF'>" >> $4
|
||
echo "<td>NIF/NIE</td><td>Nombre</td><td>Contraseña</td><td>Usuario</td>" >> $4
|
||
echo "</tr>" >> $4
|
||
echo "<tr bgcolor='#F0F8FF'>" >> $destino
|
||
echo "<td>NIF/NIE</td><td>Nombre</td><td>Contraseña</td><td>Usuario</td>" >> $destino
|
||
echo "</tr>" >> $destino
|
||
|
||
while read linea
|
||
do
|
||
... | ... | |
|
||
if [ ! -z "$nie" ]
|
||
then
|
||
login=$(ldapsearch -w $pwd -D "cn=admin,ou=People,dc=instituto,dc=extremadura,dc=es" -xLLL -h ldap -b "ou=People,dc=instituto,dc=extremadura,dc=es" "employeeNumber=$nie" "uid" | grep "uid:" | cut -f2 -d" ")
|
||
login=$(ldapsearch -w $pwd -D $user -xLLL -h ldap -b "ou=People,dc=instituto,dc=extremadura,dc=es" "employeeNumber=$nie" "uid" | grep "uid:" | cut -f2 -d" ")
|
||
if [ -z "$login" ]
|
||
then
|
||
echo " ERROR ------------> no se ha encontrado login para $nombre"
|
||
... | ... | |
else
|
||
echo " Procesando $nombre con login: $login"
|
||
fi
|
||
echo "<tr>" >> $4
|
||
echo "<td>$nie</td><td>$nombre $apellidos</td><td>$password</td><td>$login</td>" >> $4
|
||
echo "</tr>" >> $4
|
||
echo "<tr>" >> $destino
|
||
echo "<td>$nie</td><td>$nombre $apellidos</td><td>$password</td><td>$login</td>" >> $destino
|
||
echo "</tr>" >> $destino
|
||
fi
|
||
|
||
echo "$grupo:$nombre:$apellidos:$login:$password:$nie:" >> $LOG
|
||
|
||
done < "/tmp/alumtemp.txt"
|
||
rm "/tmp/alumtemp.txt"
|
||
echo "</table><br/><br/><br/>" >> $4
|
||
echo "</table><br/><br/><br/>" >> $destino
|
||
|
||
done < "/tmp/grupos2.txt"
|
||
|
||
echo "</div></body></html>" >> $4
|
||
echo "</div></body></html>" >> $destino
|
||
|
||
echo "Generado $4 correctamente."
|
||
|
||
if [ -e /usr/bin/wkhtmltopdf ]
|
||
then
|
||
echo "Generando PDF..."
|
||
nombresinext=$(basename "$4" .html)
|
||
wkhtmltopdf "$4" "$nombresinext.pdf"
|
||
echo "Generado $nombresinext.pdf correctamente."
|
||
wkhtmltopdf "$destino" "$destinopdf"
|
||
wkhtmltopdf "${destinobase}-profes.html" "${destinobase}-profes.pdf"
|
||
echo "Generado $destinopdf correctamente."
|
||
else
|
||
echo "No existe el programa /usr/bin/wkhtmltopdf, genere el PDF manualmente abriendolo con el Firefox e imprimiendolo en un archivo tipo PDF."
|
||
fi
|
Exportar a: Unified diff
Añadido listado profesores