#!/bin/bash
pvector=/usr01/home/monitor/shells/p$1vector.txt
alerta=/usr01/home/monitor/shells/alerta.txt
echo $logvector
echo Fase Tiempo H.Inicio H.Fin Utilizado Excedido
# leo en forma secuencial el archivo pvector el cual
# tiene solo 2 campos : numero de fase y tiempo
# de ejecucion
while read fase ; do
# leo los datso del archivo y se los asigno
# a las variables
fas=`echo $fase | cut -d " " -f 1`
min=`echo $fase | cut -d " " -f 2`
seg=`echo "scale=0; $min * 60" | bc`
# Busco el patron indicado y capturo la linea
# siguiente la cual contiene la fecha y hora
# de comienzo de la Fase indicada
# Si no enccuentra el PATRON se salta y lee
# el siguiente registro del archivo
if [ -f /APPADP01/home/vectprod/EXTERNOS_$3/bin/$2 ]; then
logvector=/APPADP01/home/vectprod/EXTERNOS_$3/bin/$2
elif [ -f /APPADP01/home/vectprod/EXTERNOS_$3/bin/LOG/$2 ]; then
logvector=/APPADP01/home/vectprod/EXTERNOS_$3/bin/LOG/$2
else
echo "** ARCHIVO DE LOG *** NO EXISTE *****"
read pausa
break
fi
inicio=`cat $logvector | sed -n '/^Fase '$fas'/{n;p;}'`
if [ "${inicio:-NULL}" = "NULL" ]; then
continue
fi
hor1=`echo $inicio | cut -d " " -f 4`
h11=`echo $hor1 | cut -d ":" -f 1`
h12=`echo $hor1 | cut -d ":" -f 2`
h13=`echo $hor1 | cut -d ":" -f 3`
h14=`echo "$h13 + ($h12 * 60) + ($h11 * 3600)" | bc`
h15=`echo "scale=0; $h14 / 60" | bc`
bandera=no
# Genero un ciclo infinito con el BUCLE FOR en donde
# Comienzo a consultar si existe el patron de FIN
# de la fase monitoreada - Si no encuentra el patron
# Calcula la hora transcurrida y la verifica contra
# el tiempo estimado de ejecucion
# Si el tiempo es exedido procede a enviar un correo
# para tomar las acciones que sean necesarias.
for ((;;)); do
if [ -f /APLI/home/prod/NOS_$3/bin/$2 ]; then
logvector=/APLI/home/prod/NOS_$3/bin/$2
elif [ -f /APLI/home/prod/NOS_$3/bin/LOG/$2 ]; then
logvector=/APLI/home/prod/NOS_$3/bin/LOG/$2
else
echo "** ARCHIVO DE LOG *** NO EXISTE *****"
read pausa
break
fi
final=`cat $logvector | sed -n '/^Fin Fase '$fas'/{n;p;}'`
if [ "${final:-NULL}" = "NULL" ]; then
hact2=`echo $(date) | cut -d " " -f 4`
hora1=`echo $hact2 | cut -d ":" -f 1`
hora2=`echo $hact2 | cut -d ":" -f 2`
hora3=`echo $hact2 | cut -d ":" -f 3`
hora4=`echo "scale=0; $hora3 + ($hora2 * 60) + ($hora1 * 3600)" | bc`
hora5=`echo "scale=0; $hora4 / 60" | bc`
if [ $hora5 -gt $h15 ]; then
tiempo=`echo "scale=0; $hora5 - $h15" | bc`
fi
if [ $h15 -gt $hora5 ]; then
tiempo=`echo "scale=0; ( 1440 - $h15 ) + $hora5" | bc`
fi
if [ $tiempo -gt $min ]; then
difer=`echo "$tiempo - $min" | bc`
echo `date +%Y%m%d` `date +%H:%M:%S` $logvector FASE $fas $min $hor1 $tiempo $difer >> $alerta
echo "$logvector FASE $fas $min $hor1 $tiempo $difer" | mail -s "ALERTA-VECTOR FASE $fas excedido en $difer MINUTOS" correo@tu.cl
fi
else
bandera=si
fi
# Aqui consulta la variable "bandera" si su valor
# es = a "si" procede a quebrar el bucle infinito
# es decir finaliza la fase y debera seguir
# con la siguiente
if [ $bandera = si ]; then
break
fi
sleep 900
done
hor2=`echo $final | cut -d " " -f 4`
h21=`echo $hor2 | cut -d ":" -f 1`
h22=`echo $hor2 | cut -d ":" -f 2`
h23=`echo $hor2 | cut -d ":" -f 3`
# Trasnformo la hora a minutos
h24=`echo "scale=0; $h23 + ($h22 * 60) + ($h21 * 3600)" | bc`
if [ $h24 -gt $h14 ]; then
difer=`echo "scale=0; $h24 - $h14" | bc`
else
difer=`echo "scale=0; (86400 - $h14) + $h24" | bc`
fi
if [ $h24 -eq $h14 ]; then
difer=0
fi
minutos=`echo "scale=0; $difer / 60" | bc`
resto=`echo "scale=0; $minutos - $min" | bc`
bien=1
if [ $resto -lt $bien ]; then
resto=0
fi
echo $fas $min $hor1 $hor2 $minutos $resto
done <<< "`cat $pvector`"