Script does not return complete information
Posted: Wed Feb 27, 2019 12:43 pm
Good Morning
I have the following script:
#!/bin/sh
grep=/bin/grep
cd=/bin/cd
ls=/bin/ls
awk=/bin/awk
wc=/bin/wc
cat=/bin/cat
ECHO=/bin/echo
STATE_CRITICAL=2
STATE_OK=0
cant=$1
cd /usr/local/nagios/libexec
Mydir="/usr/local/nagios/libexec"
nameLog=check_ocomc_input_event_mz
StatusError=0
:> $Mydir/tmp/$nameLog.tmp
for dir in tel gprs sms mms smsp smsbulk va roaming ; do
#cd /BRMFiles/oracle/data/ocomc/in-ocomc/$dir
if [ "roaming" = "$dir" ] ; then
CantFile=$(ls /BRMFiles/oracle/data/ocomc/in-ocomc/$dir | grep -c .edr$)
else
CantFile=$(ls /BRMFiles/oracle/data/ocomc/in-ocomc/$dir | grep -c .txt$)
fi
if [ $CantFile -ge $cant ] ; then
$ECHO "ERROR: Total archivo en el directorio $dir:$CantFile" >> $Mydir/tmp/$nameLog.tmp
StatusError=1
else
$ECHO "OK: Total archivo en el directorio $dir:$CantFile" >> $Mydir/tmp/$nameLog.tmp
fi
if [ $CantFile -gt 0 ] ; then
$ECHO "Archivo mas antiguo para $dir:$( ls -lrt /BRMFiles/oracle/data/ocomc/in-ocomc/$dir 2>/dev/null | grep -E ".txt$|.edr$" | head -1 | awk 'BEGIN {FS=" "} {print $6,$7,$8,$9}')" >> $Mydir/tmp/$nameLog.tmp
else
$ECHO "Archivo mas antiguo para $dir:No hay archivos pendientes." >> $Mydir/tmp/$nameLog.tmp
fi
TotalGeneral=$(( $TotalGeneral + $CantFile))
done
echo "Total de archivos en la entrada de OCOMC pendiente de procesar:$TotalGeneral" >> $Mydir/tmp/$nameLog.tmp
if [ $StatusError -gt 0 ] ; then
$ECHO "ERROR SE ENCUENTRA UN REZAGO DE ARCHIVOS, VER INFORMACION:";
cat $Mydir/tmp/$nameLog.tmp | $grep ERROR
cat $Mydir/tmp/$nameLog.tmp | $grep OK | $grep -v "No hay rezago en la entrada de los directorios"
Status=$STATE_CRITICAL
else
$ECHO "OK: NO HAY REZAGO EN LA ENTRADA DE LOS DIRECTORIOS DE OCOMC"
cat $Mydir/tmp/$nameLog.tmp | $grep OK
Status=$STATE_OK
fi
$ECHO " "
$ECHO "INFO ADICIONAL:"
$ECHO " "
for dir in tel gprs sms mms smsp smsbulk va roaming ; do
cat $Mydir/tmp/$nameLog.tmp | grep "Archivo mas antiguo para $dir:"
done
cat $Mydir/tmp/$nameLog.tmp | grep "OCOMC"
$ECHO "=======fin======="
exit $Status
The command line is the following:
command[check_ocomc_input_event_mz]=/usr/local/nagios/libexec/check_ocomc_input_event_mz 30
If I run the script directly on the server, I get this result:
[root@prod libexec]# ./check_ocomc_input_event_mz 30
ERROR SE ENCUENTRA UN REZAGO DE ARCHIVOS, VER INFORMACION:
ERROR: Total archivo en el directorio tel:12319
ERROR: Total archivo en el directorio sms:24076
ERROR: Total archivo en el directorio va:40
ERROR: Total archivo en el directorio roaming:112
OK: Total archivo en el directorio gprs:0
OK: Total archivo en el directorio mms:0
OK: Total archivo en el directorio smsp:18
OK: Total archivo en el directorio smsbulk:0
INFO ADICIONAL:
Archivo mas antiguo para tel:Feb 26 21:10 DGR_CTL_CEL_3G_VOZ_HIB_20190226_017815_1692.txt
Archivo mas antiguo para gprs:No hay archivos pendientes.
Archivo mas antiguo para sms:Feb 26 02:10 DGR_CTL_CEL_3G_MSGNAC_GUA_20190226_000015_730.txt
Archivo mas antiguo para mms:No hay archivos pendientes.
Archivo mas antiguo para smsp:Feb 26 10:30 DGR_CTL_CEL_SMS_CORP_20190226103005_000001_1479.txt
Archivo mas antiguo para smsbulk:No hay archivos pendientes.
Archivo mas antiguo para va:Feb 26 10:30 DGR_CTL_PLA_900_POSTPAGO_20190226_000016_798.txt
Archivo mas antiguo para roaming:Feb 26 10:15 MED_V_ARGTPCRICR05049.edr
Total de archivos en la entrada de OCOMC pendiente de procesar:36565
=======fin=======
The correct execution shows the word =======fin=======
But if I run it from Nagios it does not show all the information:
[root@nagios ~]# cat /var/www/html/infoBRM/check_ocomc_input_event_mz
ERROR SE ENCUENTRA UN REZAGO DE ARCHIVOS, VER INFORMACION:
ERROR: Total archivo en el directorio tel:12100
ERROR: Total archivo en el directorio sms:23930
ERROR: Total archivo en el directorio va:39
ERROR: Total archivo en el directorio roaming:112
OK: Total archivo en el directorio gprs:0
OK: Total archivo en el directorio mms:0
OK: Total archivo en el directorio smsp:18
OK: Total archivo en el directorio smsbulk:1
INFO ADICIONAL:
Archivo mas antiguo para tel:Feb 26 21:10 DGR_CTL_CEL_3G_VOZ_HIB_20190226_017815_1692.txt
Archivo mas antiguo para gprs:No hay archivos pendientes.
Archivo mas antiguo para sms:Feb 26 02:10 DGR_CTL_CEL_3G_MSGNAC_GUA_20190226_000015_730.txt
Archivo mas antiguo para mms:No hay archivos pendientes.
Archivo mas antiguo para smsp:Feb 26 10:30 DGR_CTL_CEL_SMS_CORP_20190226103005_000001_1479.txt
Archivo mas antiguo para smsbulk:Feb 27 11:20 DGR_CTL_CEL_3G_MSGNAC_GUA_20190227_000086_730.txt
Archivo mas antiguo para va:Feb 26 10:30 DGR_CTL_PLA_900_POSTPAGO_20190226_000016_798.txt
Archi
[root@nagios ~]#
What should I do to correct this problem?
Best regards...
I have the following script:
#!/bin/sh
grep=/bin/grep
cd=/bin/cd
ls=/bin/ls
awk=/bin/awk
wc=/bin/wc
cat=/bin/cat
ECHO=/bin/echo
STATE_CRITICAL=2
STATE_OK=0
cant=$1
cd /usr/local/nagios/libexec
Mydir="/usr/local/nagios/libexec"
nameLog=check_ocomc_input_event_mz
StatusError=0
:> $Mydir/tmp/$nameLog.tmp
for dir in tel gprs sms mms smsp smsbulk va roaming ; do
#cd /BRMFiles/oracle/data/ocomc/in-ocomc/$dir
if [ "roaming" = "$dir" ] ; then
CantFile=$(ls /BRMFiles/oracle/data/ocomc/in-ocomc/$dir | grep -c .edr$)
else
CantFile=$(ls /BRMFiles/oracle/data/ocomc/in-ocomc/$dir | grep -c .txt$)
fi
if [ $CantFile -ge $cant ] ; then
$ECHO "ERROR: Total archivo en el directorio $dir:$CantFile" >> $Mydir/tmp/$nameLog.tmp
StatusError=1
else
$ECHO "OK: Total archivo en el directorio $dir:$CantFile" >> $Mydir/tmp/$nameLog.tmp
fi
if [ $CantFile -gt 0 ] ; then
$ECHO "Archivo mas antiguo para $dir:$( ls -lrt /BRMFiles/oracle/data/ocomc/in-ocomc/$dir 2>/dev/null | grep -E ".txt$|.edr$" | head -1 | awk 'BEGIN {FS=" "} {print $6,$7,$8,$9}')" >> $Mydir/tmp/$nameLog.tmp
else
$ECHO "Archivo mas antiguo para $dir:No hay archivos pendientes." >> $Mydir/tmp/$nameLog.tmp
fi
TotalGeneral=$(( $TotalGeneral + $CantFile))
done
echo "Total de archivos en la entrada de OCOMC pendiente de procesar:$TotalGeneral" >> $Mydir/tmp/$nameLog.tmp
if [ $StatusError -gt 0 ] ; then
$ECHO "ERROR SE ENCUENTRA UN REZAGO DE ARCHIVOS, VER INFORMACION:";
cat $Mydir/tmp/$nameLog.tmp | $grep ERROR
cat $Mydir/tmp/$nameLog.tmp | $grep OK | $grep -v "No hay rezago en la entrada de los directorios"
Status=$STATE_CRITICAL
else
$ECHO "OK: NO HAY REZAGO EN LA ENTRADA DE LOS DIRECTORIOS DE OCOMC"
cat $Mydir/tmp/$nameLog.tmp | $grep OK
Status=$STATE_OK
fi
$ECHO " "
$ECHO "INFO ADICIONAL:"
$ECHO " "
for dir in tel gprs sms mms smsp smsbulk va roaming ; do
cat $Mydir/tmp/$nameLog.tmp | grep "Archivo mas antiguo para $dir:"
done
cat $Mydir/tmp/$nameLog.tmp | grep "OCOMC"
$ECHO "=======fin======="
exit $Status
The command line is the following:
command[check_ocomc_input_event_mz]=/usr/local/nagios/libexec/check_ocomc_input_event_mz 30
If I run the script directly on the server, I get this result:
[root@prod libexec]# ./check_ocomc_input_event_mz 30
ERROR SE ENCUENTRA UN REZAGO DE ARCHIVOS, VER INFORMACION:
ERROR: Total archivo en el directorio tel:12319
ERROR: Total archivo en el directorio sms:24076
ERROR: Total archivo en el directorio va:40
ERROR: Total archivo en el directorio roaming:112
OK: Total archivo en el directorio gprs:0
OK: Total archivo en el directorio mms:0
OK: Total archivo en el directorio smsp:18
OK: Total archivo en el directorio smsbulk:0
INFO ADICIONAL:
Archivo mas antiguo para tel:Feb 26 21:10 DGR_CTL_CEL_3G_VOZ_HIB_20190226_017815_1692.txt
Archivo mas antiguo para gprs:No hay archivos pendientes.
Archivo mas antiguo para sms:Feb 26 02:10 DGR_CTL_CEL_3G_MSGNAC_GUA_20190226_000015_730.txt
Archivo mas antiguo para mms:No hay archivos pendientes.
Archivo mas antiguo para smsp:Feb 26 10:30 DGR_CTL_CEL_SMS_CORP_20190226103005_000001_1479.txt
Archivo mas antiguo para smsbulk:No hay archivos pendientes.
Archivo mas antiguo para va:Feb 26 10:30 DGR_CTL_PLA_900_POSTPAGO_20190226_000016_798.txt
Archivo mas antiguo para roaming:Feb 26 10:15 MED_V_ARGTPCRICR05049.edr
Total de archivos en la entrada de OCOMC pendiente de procesar:36565
=======fin=======
The correct execution shows the word =======fin=======
But if I run it from Nagios it does not show all the information:
[root@nagios ~]# cat /var/www/html/infoBRM/check_ocomc_input_event_mz
ERROR SE ENCUENTRA UN REZAGO DE ARCHIVOS, VER INFORMACION:
ERROR: Total archivo en el directorio tel:12100
ERROR: Total archivo en el directorio sms:23930
ERROR: Total archivo en el directorio va:39
ERROR: Total archivo en el directorio roaming:112
OK: Total archivo en el directorio gprs:0
OK: Total archivo en el directorio mms:0
OK: Total archivo en el directorio smsp:18
OK: Total archivo en el directorio smsbulk:1
INFO ADICIONAL:
Archivo mas antiguo para tel:Feb 26 21:10 DGR_CTL_CEL_3G_VOZ_HIB_20190226_017815_1692.txt
Archivo mas antiguo para gprs:No hay archivos pendientes.
Archivo mas antiguo para sms:Feb 26 02:10 DGR_CTL_CEL_3G_MSGNAC_GUA_20190226_000015_730.txt
Archivo mas antiguo para mms:No hay archivos pendientes.
Archivo mas antiguo para smsp:Feb 26 10:30 DGR_CTL_CEL_SMS_CORP_20190226103005_000001_1479.txt
Archivo mas antiguo para smsbulk:Feb 27 11:20 DGR_CTL_CEL_3G_MSGNAC_GUA_20190227_000086_730.txt
Archivo mas antiguo para va:Feb 26 10:30 DGR_CTL_PLA_900_POSTPAGO_20190226_000016_798.txt
Archi
[root@nagios ~]#
What should I do to correct this problem?
Best regards...