So simple and so not working at the same time..
#!/usr/bin/env bash
RES=$(tail -1 $1)
VAR2=$(grep -oh $2 $1 | tail -1)
VAR3=$(grep -oh $3 $1 | tail -1)
#echo "res=${RES} | var2=${VAR2} - var3=${VAR3}"
#exit 0
if [ ! -f $1 ]; then
echo "Log file not found"
exit 3
else
if [[ ${RES} == ${VAR2} && ${RES} != ${VAR3} ]]; then
echo $RES
exit 0
fi
if [[ ${RES} == ${VAR2} && ${RES} == ${VAR3} ]]; then
echo $RES
exit 1
fi
if [[ ${RES} != ${VAR2} && ${RES} == ${VAR3} ]]; then
echo $RES
exit 2
fi
echo $RES
exit 3
fi
This is a nagios script that helps me to read log files. I call this script (from nagios) with /usr/local/.../read_log.sh OK NOK
If I uncomment
#echo "res=${RES} | var2=${VAR2} - var3=${VAR3}"
#exit 0
I see from Nagios
Status Information: res=Backup of Monday: OK: Backup of CURRENT: NOK
Performance Data: var2=OK - var3=NOK
Which should be the 2nd IF with exit 1. But it won't and no matter what, it always go for Unable to read output
both if log contain OK and/OR NOK
Aucun commentaire:
Enregistrer un commentaire