source: client/shared/bin/poweroffconf @ 96d7f3f

918-git-images-111dconfigfileconfigure-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-instalacionwebconsole3
Last change on this file since 96d7f3f was b608176, checked in by ramon <ramongomez@…>, 14 years ago

Versión 1.0.2: Script que debe ejecutarse en el cron del sistema para comprobar el periodo de inactividad del cliente y lanzar el proceso de apagado (modifica #451).

git-svn-id: https://opengnsys.es/svn/branches/version1.0@2363 a21b9725-9963-47de-94b9-378ad31fedc9

  • Property mode set to 100755
File size: 2.2 KB
Line 
1#!/bin/bash
2#/**
3#@file     poweroffconf
4#@brief    Control de parada tras tiempo de inactividad para ahorro de energía.
5#@param    int_minutos    Minutos de inactividad (opcional).
6#@note     La comprobación periódica debe ejecutarse en el "cron" del sistema.
7#@note     Fichero de configuración: /etc/poweroff.conf
8#@author   Ramón Gómez - Univ. Sevilla
9#@date     2011-10-25
10#@warning  License: GNU GPLv3+
11#*/
12
13
14# Variables generales.
15OPENGNSYS=${OPENGNSYS:-/opt/opengnsys}  # Instalación de OpenGnSys
16OGETC=${OGETC:-$OPENGNSYS/etc}          # Configuración de OpenGnSys
17POWEROFFCONF=/etc/poweroff.conf         # Configuración del script
18source $POWEROFFCONF
19
20case $# in
21    0)  # Sin parámetros, comprobar que existe la variable POWEROFFSLEEP.
22        if [ -z "$POWEROFFSLEEP" ]; then
23             ogRaiseError $OG_ERR_FORMAT "Sin tiempo de espera."
24             exit $?
25        fi
26        ;;
27    1)  #TODO Comprobar que el parámetro es entero positivo.
28        # Nuevo timepo de espera.
29        POWEROFFSLEEP=$1
30        perl -pi -e "s/POWEROFFSLEEP=.*/POWEROFFSLEEP=$POWEROFFSLEEP/" $POWEROFFCONF
31        # Si se necesita, recalcular tiempo de parada.
32        if [ -n "POWEROFFTIME" ]; then
33            POWEROFFTIME=$(date --date="$POWEROFFSLEEP min" +"%H%M")
34            perl -pi -e "s/POWEROFFTIME=.*/POWEROFFTIME=$POWEROFFTIME/" $POWEROFFCONF
35        fi
36        exit 0 ;;
37    *)  # Error de formato de ejecución.
38        ogRaiseError $OG_ERR_FORMAT "Formato: $0 [int_minutos]"
39        exit $? ;;
40esac
41# Comprobar si hay algún script en ejecución.
42if [ -n "$(pgrep -fl $OPENGNSYS | egrep -v "$OGETC|$0")" ]; then
43    # Eliminar tiempo de inicio de espera, si se está ejecutando operación.
44    perl -pi -e 's/POWEROFFTIME=.*$/POWEROFFTIME=/' $POWEROFFCONF
45else
46    # Si el sistema está en estado de espera, ...
47    NOW=$(date +"%H%M")
48    if [ -z "$POWEROFFTIME" ]; then
49        # Asignar tiempo de inicio, si no estaba definido.
50        POWEROFFTIME=$(date --date="$POWEROFFSLEEP min" +"%H%M")
51        perl -pi -e "s/POWEROFFTIME=.*$/POWEROFFTIME=$POWEROFFTIME/" $POWEROFFCONF
52    else
53        # Apagar el equipo si se sobrepasa el periodo de espera.
54        if [ $NOW -ge $POWEROFFTIME ]; then
55            $OPENGNSYS/scripts/poweroff
56        fi
57    fi
58fi
59
Note: See TracBrowser for help on using the repository browser.