-
Notifications
You must be signed in to change notification settings - Fork 16
/
megablink
executable file
·61 lines (50 loc) · 1.34 KB
/
megablink
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/usr/bin/perl
use strict;
use warnings;
use Data::Dumper;
use Carp;
use English qw( -no_match_vars );
use Getopt::Long;
our $VERSION = 0.3;
# root or die
my $username = ( getpwuid $EUID );
croak "megacli requires root" if $username ne 'root';
# CLI arguments
my $unblink = 0;
GetOptions(
'u|unblink' => \$unblink,
) or croak "error in command line args";
croak "no arguments... please specify which drives to blink" unless scalar @ARGV;
my @drives = @ARGV;
# pull in megamap
my $megamap = `megamap`;
my @maplines = split /\n/, $megamap;
if ( scalar(@maplines) == 0 ) {
warn "No output from megamap\n";
exit 2;
}
my %map;
foreach my $line (@maplines) {
chomp($line);
my ( $megaraid_id, $linux_drive, $wwn ) = split( /\t/, $line );
$map{$linux_drive} = $megaraid_id;
}
# blink all the drives!
foreach my $drive (@drives) {
$drive =~ s{^/dev/}{}x;
unless ( $drive =~ /^sd[a-z][a-z]?$/x or $drive =~ /^\d+$/ ) {
croak "invalid drive spec '$drive', try sdc or 13";
}
my $megaraid_id;
if ( $drive =~ /^\d+$/ ) {
$megaraid_id = $drive;
} else {
$megaraid_id = $map{$drive}
}
croak "no mapping for $drive" unless defined $megaraid_id;
print "blinking drive $megaraid_id ($drive), ";
my $gonogo = $unblink ? "stop" : "-start";
my $cmd = "megacli -PdLocate $gonogo -physdrv[0:$megaraid_id] -a0";
print "running $cmd\n";
system($cmd);
}