-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathhpsa-smartctl
executable file
·87 lines (71 loc) · 2.06 KB
/
hpsa-smartctl
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#!/usr/bin/perl
#
# Helper-script to issue smartctl commands to all disks connected
# to HP/HPE Smart Array controllers using the hpsa driver (ie. Px1x and newer)
#
# Written by Niklas Edmundsson in January 2017
# Copyright (C) 2017-2020 Niklas Edmundsson <nikke@acc.umu.se>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published
# by the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
use warnings;
use strict;
sub debug
{
my(@a) = @_;
if($ENV{DEBUG}) {
print STDERR @a,"\n";
}
}
my @sgdevs;
die "Usage: $0 smartctl-flags" unless($ARGV[0]);
my $args = "";
foreach my $arg (@ARGV) {
$args.=" " if($args);
$args .= $arg;
}
# Find sg devices used by Smart Array controllers
foreach(`lsscsi -g`) {
chomp;
my ($scsi, $type, $vendor, $model, $rev, $dev, $sg) = split(/\s+/);
next unless($type eq 'storage');
push @sgdevs, $sg;
}
my $rc = 0;
# Emit commands to all controllers
foreach my $sg (@sgdevs) {
# Drives are listed first with no gaps. Find the highest one by
# doing inquiry
my $lastdrive=-1;
foreach my $unit (0 .. 63) {
my $cmd = "smartctl -i -q silent -d cciss,$unit $sg";
debug("cmd: ", $cmd);
system($cmd);
my $ret = $? >> 8;
debug("ret: $ret");
last if($ret != 0);
$lastdrive=$unit;
}
next if($lastdrive < 0);
debug("lastdrive: $lastdrive");
foreach my $unit (0 .. $lastdrive) {
my $cmd = "smartctl $args -d cciss,$unit $sg";
debug("cmd: ", $cmd);
print `$cmd`;
my $ret = $? >> 8;
debug("ret: $ret");
# smartctl return code is a bitmask, set all bits found
$rc |= $ret;
}
}
exit $rc;