code unified with ansible-initial-server-setup/.../hddtemp
Synced with https://github.com/spacelama/ansible-initial-server-setup -> hddtemp purpose comment taken from ansible-initial-server-setup/.../smart-intercept-spindown
This commit is contained in:
parent
74b8adc61c
commit
7e4a2338d3
1 changed files with 20 additions and 3 deletions
23
hddtemp
23
hddtemp
|
|
@ -1,16 +1,31 @@
|
||||||
#!/usr/bin/perl
|
#!/usr/bin/perl
|
||||||
|
|
||||||
|
# A replacement for the various stock versions of hddtemp that all
|
||||||
|
# seem to have big issues with different types of drives, or spin up
|
||||||
|
# drives that are in powersaving spun-down mode, etc.
|
||||||
|
|
||||||
|
# For those disks like some of my SAS drives where `smartctl
|
||||||
|
# --nocheck=standby` and `hdparm -C` actually spins up the disk,
|
||||||
|
# detect whether a disk is spun down with sdparm commands, and don't
|
||||||
|
# invoke smartctl if it is. Otherwise, some of our other disks like
|
||||||
|
# our 16TB SATA drives on Dell Perc controllers give unreliable status to `sdparm
|
||||||
|
# --command=sense`, but `smartctl --nocheck=standby` does seem to
|
||||||
|
# reliably detect their spundown state anyway, so we continue to
|
||||||
|
# supply `--nocheck=standby` to cover this case.
|
||||||
|
|
||||||
|
# Much of this stolen from /etc/munin/plugins/hddtemp_smartctl
|
||||||
|
|
||||||
use strict;
|
use strict;
|
||||||
use warnings;
|
use warnings;
|
||||||
|
|
||||||
# much of this stolen from /etc/munin/plugins/hddtemp_smartctl
|
|
||||||
|
|
||||||
$ENV{PATH}="$ENV{PATH}:/usr/sbin:/sbin";
|
$ENV{PATH}="$ENV{PATH}:/usr/sbin:/sbin";
|
||||||
|
|
||||||
|
my $last_exit=0;
|
||||||
foreach my $drive (@ARGV) {
|
foreach my $drive (@ARGV) {
|
||||||
my $sense=`sdparm --command=sense $drive 2>/dev/null`;
|
my $sense=`sdparm --command=sense $drive 2>/dev/null`;
|
||||||
if (!($sense =~ /Standby/)) {
|
if (!($sense =~ /Standby/)) {
|
||||||
my $output=`smartctl -A -i --nocheck=standby $drive`;
|
my $output=`smartctl -A -i --nocheck=standby,0 $drive`;
|
||||||
|
$last_exit = $?>>8;
|
||||||
|
|
||||||
my $model="";
|
my $model="";
|
||||||
if ($output =~ /(Model Number|Device Model):\s*(.*)/) {
|
if ($output =~ /(Model Number|Device Model):\s*(.*)/) {
|
||||||
|
|
@ -36,3 +51,5 @@ foreach my $drive (@ARGV) {
|
||||||
print "$drive: Sleeping. Temperature not available\n";
|
print "$drive: Sleeping. Temperature not available\n";
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
exit $last_exit;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue