Created
December 1, 2015 10:24
-
-
Save zas/99688bf4cac4e149a2d7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl | |
use warnings; | |
use strict; | |
=pod | |
C<tw_cli info c0 u0> example output: | |
Unit UnitType Status %RCmpl %V/I/M Port Stripe Size(GB) | |
------------------------------------------------------------------------ | |
u0 RAID-1 OK - - - - 232.82 | |
u0-0 DISK OK - - p0 - 232.82 | |
u0-1 DISK OK - - p2 - 232.82 | |
=cut | |
(@ARGV == 2 | |
and $ARGV[0] =~ /\Ac[0-9]\z/ | |
and $ARGV[1] =~ /\Au[0-9]\z/ | |
) or die "Usage: $0 c# u#\n"; | |
my ($cx, $ux) = @ARGV; | |
my $output = `sudo tw_cli info $cx $ux 2>&1`; | |
my $rc = $?; | |
my ($line, $type, $status) = $output =~ /^($ux \s+ (\S+) \s+ (\S+) .*)$/mx; | |
$line =~ s/\s+/ /g if defined $line; | |
if ($rc == 0 and defined($status) and $status eq "OK") | |
{ | |
print "OK: $line\n"; | |
exit 0; | |
} | |
print "ERROR"; | |
print " (rc=$?)" if $rc; | |
print ": "; | |
print(defined($line) ? $line : "Could not parse output of tw_cli"); | |
print "\n"; | |
exit 2; | |
# eof |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment