<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">#! /usr/bin/env perl


use strict;

use warnings;

# use feature qw(say fc);


use constant megacli=&gt;'/opt/MegaRAID/MegaCli/MegaCli';


use Getopt::Std 'getopts';

use Pod::Usage 'pod2usage';


our(%options);

getopts('A:E:S:pligchb', \%options);


my(%megacli)=
(

adapter=&gt;$options{A}||=0,

enclosure=&gt;$options{E}||=0,

slot=&gt;$options{S}||=0 # 2

);

my($megacli);


if(defined($options{p}))
{

$megacli=
"
@{[megacli]}

-pdrbld

-showprog

-physdrv '[$megacli{enclosure}:$megacli{slot}]'

-a$megacli{adapter}
";

}

elsif(defined($options{l}))
{

$megacli=
"
@{[megacli]}

-pdlist

-a$megacli{adapter}

| less +/'Firmware state:'
"; # eg. Unconfigured(good), Spun Up # look for: Slot Number: (eg. 2)
}

elsif(defined($options{i}))
{

$megacli=
"
@{[megacli]}

-pdinfo

-physdrv '[$megacli{enclosure}:$megacli{slot}]'

-a$megacli{adapter}

| less +/'Firmware state:'
"; # narrow down (the same output as above)

}

elsif(defined($options{g}))
{

$megacli=
"
@{[megacli]}

-pdmakegood

-physdrv '[$megacli{enclosure}:$megacli{slot}]'

-a$megacli{adapter}
"; # make good (if not already)

}

elsif(defined($options{c}))
{

$megacli=
"
@{[megacli]}

-cfgforeign

-clear

-a$megacli{adapter}
"; # clear 'This Drive is Foreign' (appended at the end of output) if foreign

}


elsif(defined($options{h}))
{

$megacli=
"
@{[megacli]}

-pdhsp

-set

-physdrv '[$megacli{enclosure}:$megacli{slot}]'

-a$megacli{adapter}
"; # set as hotspare # Adapter: 0: Set Physical Drive at EnclId-0 SlotId-2 as Hot Spare Success. (follows)

}

elsif(defined($options{b}))
{

$megacli=
"
@{[megacli]}

-pdrbld

â€“start

â€“physdrv '[$megacli{enclosure}:$megacli{slot}]'

â€“a$megacli{adapter}
"; # manually start rebuild (if fails; replace drive otherwise)

}

else
{

pod2usage();

}


$megacli=~s/\n/ /g;


exec($megacli);


=pod


=head1 name

megacli.pl - megaraid interface


=head1 SYNOPSIS

megacli.pl [-A &lt;adapter&gt;] [-E &lt;enclosure&gt;] [-S &lt;slot&gt;] { -p | -l | -i | -g | -c | -h | -b }


=head1 description

interface to lsi megaraid raid controller


=head1 options

=over


=item -A adapter

=item -E enclosure

=item -S slot


=item -p progress

=item -l list

=item -i information

=item -g make good

=item -c clear foreign

=item -h hot spare

=item -b build manually


=back


=head1 notes

written for C&lt;perl, v5.8.8&gt;

tested with C&lt;LSI Logic / Symbios Logic MegaRAID SAS 1078 (rev 04)&gt;


=head1 see also

MegaCli(8), less(1)


L&lt;paper by jim sullivan (cisco systems)|https://community.cisco.com/kxiwq67737/attachments/kxiwq67737/4561-docs-security/907/1/43204-CIVS-HDD.pdf&gt;


=head1 copyright

public domain


=head1 author

anonymous


=cut
</pre></body></html>