forked from NoLooseEnds/Scripts
-
Notifications
You must be signed in to change notification settings - Fork 10
/
hddtemp
executable file
·38 lines (33 loc) · 1.16 KB
/
hddtemp
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
#!/usr/bin/perl
use strict;
use warnings;
# much of this stolen from /etc/munin/plugins/hddtemp_smartctl
$ENV{PATH}="$ENV{PATH}:/usr/sbin:/sbin";
foreach my $drive (@ARGV) {
my $sense=`sdparm --command=sense $drive 2>/dev/null`;
if (!($sense =~ /Standby/)) {
my $output=`smartctl -A -i --nocheck=standby $drive`;
my $model="";
if ($output =~ /(Model Number|Device Model):\s*(.*)/) {
$model="$2: ";
}
if ($output =~ /Current Drive Temperature:\s*(\d+)/) {
print "$drive: $model$1°C\n";
} elsif ($output =~ /^(194 Temperature_(Celsius|Internal).*)/m) {
my @F = split /\s+/, $1;
print "$drive: $model$F[9]°C\n";
} elsif ($output =~ /^(231 Temperature_Celsius.*)/m) {
my @F = split ' ', $1;
print "$drive: $model$F[9]°C\n";
} elsif ($output =~ /^(190 (Airflow_Temperature_Cel|Temperature_Case).*)/m) {
my @F = split ' ', $1;
print "$drive: $model$F[9]°C\n";
} elsif ($output =~ /Temperature:\s*(\d+) Celsius/) {
print "$drive: $model$1°C\n";
} else {
print "$drive: Smart not available\n";
}
} else {
print "$drive: Sleeping. Temperature not available\n";
};
}