#1009264 hddtemp wakes up non ATA drives

#1009264#5
Date:
2022-04-10 13:21:46 UTC
From:
To:
hddtemp(1) shows that --wake-up is only relevant for ATA drives.  My
testing confirms this - hddtemp /dev/sdb first returns an incorrect
error, but spins up the drive anyway, then it starts to succeed:


tconnors@pve:~$ sudo hddtemp /dev/sdb
/dev/sdb: SEAGATE ST4000NM0023:  drive supported, but it doesn't have a temperature sensor.
tconnors@pve:~$ sudo hddtemp /dev/sdb
/dev/sdb: SEAGATE ST4000NM0023: 44°C

Just like https://www.smartmontools.org/ticket/1586 (I don't believe
hddtemp links against smartmontools), there are ways to get the wake
status of non ATA disks, and hddtemp should default to not waking up
sleeping drives.

 tconnors@pve:~$ for i in /dev/sd[b-gi-z] ; do echo $i ; sudo sdparm --command=sense $i ; done
/dev/sdb

    /dev/sdb: SEAGATE ST4000NM0023 XMGJ

/dev/sdc

    /dev/sdc: SEAGATE ST4000NM0023 XMGJ

/dev/sdd

    /dev/sdd: SEAGATE ST6000NM0095 DS22

/dev/sde

    /dev/sde: SEAGATE ST4000NM0023 XMGJ

/dev/sdf

    /dev/sdf: SEAGATE ST6000NM0095 DS22

/dev/sdg

    /dev/sdg: TOSHIBA MG04SCA60EE DR07

/dev/sdi

    /dev/sdi: ATA WDC WD10EAVS-32D 1A01

tconnors@pve:~$ for i in /dev/sd[b-gi-z] ; do echo $i ; sudo sg_start -r --pc=3 $i & done ; wait
/dev/sdb
[1] 1840017
/dev/sdc
[2] 1840018
/dev/sdd
[3] 1840019
/dev/sde
[4] 1840020
/dev/sdf
[5] 1840021
/dev/sdg
[6] 1840022
/dev/sdi
[7] 1840023
Illegal request
START STOP UNIT command failed
sg_start failed: Illegal request

tconnors@pve:~$ for i in /dev/sd[b-gi-z] ; do echo $i ; sudo sdparm --command=sense $i ; done
/dev/sdb

    /dev/sdb: SEAGATE ST4000NM0023 XMGJ

Additional sense: Standby condition activated by command
/dev/sdc

    /dev/sdc: SEAGATE ST4000NM0023 XMGJ

Additional sense: Standby condition activated by command
/dev/sdd

    /dev/sdd: SEAGATE ST6000NM0095 DS22

Additional sense: Standby condition activated by command
/dev/sde

    /dev/sde: SEAGATE ST4000NM0023 XMGJ

Additional sense: Standby condition activated by command
/dev/sdf

    /dev/sdf: SEAGATE ST6000NM0095 DS22

Additional sense: Standby condition activated by command
/dev/sdg

    /dev/sdg: TOSHIBA MG04SCA60EE DR07

Additional sense: Standby condition activated by command
/dev/sdi

    /dev/sdi: ATA WDC WD10EAVS-32D 1A01

#1009264#10
Date:
2024-12-30 14:57:53 UTC
From:
To:
For those who want a somewhat compatible replacement that doesn't spin up
drives, I've been using this succesfully for some years across a wide
range of hardware:

: 55962,2; cat /usr/local/bin/hddtemp
#!/usr/bin/perl

use strict;
use warnings;

# much of this stolen from /usr/share/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";
  };
}