I'm trying to write a shell script for nagios plugin. I have a list of failed nodes where I have to trigger a CRITICAL alert to the nagios.
#cat file OFFLINE OFFLINE OFFLINE OFFLINE
All I want is to send exit status(i.e 2) for all the OFFLINE nodes. And, here is my code below so far.
while read -r output; do STATE=$(echo $output) if [ $STATE == "OFFLINE" ]; then echo "CRITICAL: STATE is $STATE" exit 2 else echo "OK " > /dev/null fi done< <( cat file )
But the problem is the loop runs for one time and exits with 2 and alert goes for one node and for the remaining node I need to send the alert. Is there any way to write this script?