By the way, putting your code in <c>...</c> tags will simplify things for both you and us.
Applying ysth's advice, we get:
#!/usr/bin/perl
use strict;
use warnings;
my $non_running = 0;
my @zones = qx{zoneadm list -ip};
foreach (@zones) {
my ($id, $name, $state) = split(/:/, $_);
if($state eq "running") {
print "OK: zone $name is in running state\n";
} else {
print "CRITICAL: Zone $name is in $state\n";
$non_running = 1;
}
}
if ($non_running) {
exit 2;
} else {
exit 0;
}
Hopefully, you've learned about else in the process. |