Your code exits on the first controller no matter what. The answer is simple: Don't exit from within your loop. Keep status information, then exit after checking all controllers.
Simplest version: > retval=0 > for c in $controllers; > do sudo /usr/bin/tw_cli info $c | grep -eq "DEVICE-ERROR|DEGRADED| > INOPERABLE|SMART-FAILURE" > if [ $? -eq 0 ]; then > echo "Critical: raid problem with controller $c"; > retval=2 > fi > echo "Ok: Controller $c is fine" > done > exit $retval This will output (for example): Ok: Controller c0 is fine Ok: Controller c1 is fine Critical: raid problem with controller c2 Ok: Controller c3 is fine and then return 2. For further help with bash scripting, might I suggest the Advanced Bash-Scripting Guide at http://tldp.org/LDP/abs/html/ Also, please read http://nagios.sourceforge.net/docs/3_0/pluginapi.html to learn how to format multi-line output from your plugin. --Rick On Wed, Aug 18, 2010 at 8:27 AM, Kaushal Shriyan <[email protected]> wrote: > Hi, > > I have the below bash script for nagios plugin. The issue is that i > dont need to hard code the controller c0 or c1 or c2 or c3. so on some > servers there may be two controllers c0, and c1 and on some server > there may be four controllers c0,1,2 and 3. I dont know it off hand > > Typically if i run tw_cli info i get > > tw_cli info > > Ctl Model Ports Drives Units NotOpt RRate VRate > BBU > ------------------------------------------------------------------------ > c0 9550SX-8LP 8 8 4 0 1 1 > OK > c1 9550SX-8LP 8 8 2 0 1 1 > OK > > ##################################################################################################### > controllers=$(tw_cli info | awk '/^c[0-9]/{print $1}) > for c in $controllers; > do sudo /usr/bin/tw_cli info $c | grep -eq "DEVICE-ERROR|DEGRADED| > INOPERABLE|SMART-FAILURE" > if [ $? -eq 0 ]; then > echo "Critical: raid problem with controller $c"; > exit 2 > fi > echo "Ok:raid is fine" > exit 0 > done > ##################################################################################################### > > The issue with the above bash script is that it will exit with 2 if > the controller c0 fail and it wont check for other controllers. > I need to check for other controllers too at the same time > > Please suggest. > > Thanks, > > Kaushal > > ------------------------------------------------------------------------------ > This SF.net email is sponsored by > > Make an app they can't live without > Enter the BlackBerry Developer Challenge > http://p.sf.net/sfu/RIM-dev2dev > _______________________________________________ > Nagios-users mailing list > [email protected] > https://lists.sourceforge.net/lists/listinfo/nagios-users > ::: Please include Nagios version, plugin version (-v) and OS when reporting > any issue. > ::: Messages without supporting info will risk being sent to /dev/null > ------------------------------------------------------------------------------ This SF.net email is sponsored by Make an app they can't live without Enter the BlackBerry Developer Challenge http://p.sf.net/sfu/RIM-dev2dev _______________________________________________ Nagios-users mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/nagios-users ::: Please include Nagios version, plugin version (-v) and OS when reporting any issue. ::: Messages without supporting info will risk being sent to /dev/null
