918-git-images-111dconfigure-oglivegit-imageslgromero-new-oglivemainmaint-cronmount-efivarfsmultivmmultivm-ogboot-installerogClonningEngineogboot-installer-jenkinsoglive-ipv6test-python-scriptsticket-301ticket-50ticket-50-oldticket-577ticket-585ticket-611ticket-612ticket-693ticket-700ubu24tplunification2use-local-agent-oglivevarios-instalacion
Line | |
---|
1 | #!/bin/bash |
---|
2 | # listclientlive: Lista la distribución ogLive asociada a los clientes, |
---|
3 | # ya sea un equipo o un aula. |
---|
4 | # Uso: listclienlive NombrePC | NombreAula |
---|
5 | # Autor: Ramón M. Gómez - Univ. Sevilla, junio 2017 |
---|
6 | |
---|
7 | |
---|
8 | # Variables. |
---|
9 | PROG=$(basename "$0") |
---|
10 | OPENGNSYS=${OPENGNSYS:-"/opt/opengnsys"} |
---|
11 | SERVERCONF=$OPENGNSYS/etc/ogAdmServer.cfg |
---|
12 | TFTPDIR=$OPENGNSYS/tftpboot |
---|
13 | MYCNF=/tmp/.my.cnf.$$ |
---|
14 | |
---|
15 | # Control básico de errores. |
---|
16 | if [ $# -ne 1 ]; then |
---|
17 | echo "$PROG: Error de ejecución" >&2 |
---|
18 | echo "Formato: $PROG [NOMBRE_PC|NOMBRE_AULA]" >&2 |
---|
19 | exit 1 |
---|
20 | fi |
---|
21 | if [ ! -r $SERVERCONF ]; then |
---|
22 | echo "$PROG: Sin acceso a fichero de configuración" >&2 |
---|
23 | exit 2 |
---|
24 | fi |
---|
25 | |
---|
26 | # Obtener datos de acceso a la Base de datos. |
---|
27 | source $SERVERCONF |
---|
28 | # Sustituir caracteres ' por \' para evitar inyección SQL. |
---|
29 | RESOURCE="${1//\'/\'}" |
---|
30 | # Componer fichero con credenciales de conexión. |
---|
31 | touch $MYCNF |
---|
32 | chmod 600 $MYCNF |
---|
33 | cat << EOT > $MYCNF |
---|
34 | [client] |
---|
35 | user=$USUARIO |
---|
36 | password=$PASSWORD |
---|
37 | EOT |
---|
38 | # Borrar el fichero temporal si termina el proceso. |
---|
39 | trap "rm -f $MYCNF" 0 1 2 3 6 9 15 |
---|
40 | # Obtener nombre de ordenador individual o todos los de una aula e indicar su plantilla asociada. |
---|
41 | mysql --defaults-extra-file="$MYCNF" -D "$CATALOG" -s -N -e \ |
---|
42 | "SELECT ord.nombreordenador, ord.oglivedir |
---|
43 | FROM ordenadores AS ord |
---|
44 | JOIN aulas USING (idaula) |
---|
45 | WHERE aulas.nombreaula='$RESOURCE' |
---|
46 | OR ord.nombreordenador='$RESOURCE';" | \ |
---|
47 | while read -r PC OGLIVE; do |
---|
48 | echo "Equipo \"$PC\" asociado a cliente \"$OGLIVE\" $([ -e $TFTPDIR/$OGLIVE ] || echo "(inexistente)")" |
---|
49 | done |
---|
50 | |
---|
Note: See
TracBrowser
for help on using the repository browser.