¿Qué comando o programa de terminal puede enumerar las horas de encendido de un SSD?

Estoy buscando un script usando el shell de Unix para recuperar los datos de SSD (y HDD) que la utilidad de disco muestra en la ventana de información.

Información de la utilidad de disco

Inmediatamente me interesan las horas de encendido y el ciclo de encendido, pero si todos los datos provienen de una estructura de datos o herramienta, mucho mejor. Las herramientas habituales diskutil info disk0y ioreg -lno producen los valores "de interés" enumerados en la captura de pantalla anterior.

¿Esta información está disponible en alguna de las herramientas de terminal OS X integradas o necesito encontrar un paquete de código abierto que haga las mismas llamadas API para obtener este nivel de detalle sobre una unidad Mac?

Respuestas (2)

El comando que me funciona en 2019 es:

smartctl -a disk0 | grep -i hours

La instalación de Homebrew es probablemente la más fácil y aquí hay algunos detalles sobre la instalación y el uso de la herramienta.


smartmontoolses un paquete de código abierto que proporciona la mayoría de los valores que le interesan.

Si usa Homebrew , instálelo con:

brew install smartmontools

(En la instalación estándar de Homebrew, los comandos se instalan en /usr/local/bin).

De lo contrario, descárguelo de https://www.smartmontools.org/wiki/Download y compílelo como de costumbre:

$ cd smartmontools-6.0
$ ./configure 
$ make
$ sudo make install

(A menos que se especifique lo contrario como una opción para ./configure, los smartmontoolscomandos se instalan en /usr/local/sbin, así que actualice la $PATHvariable si es necesario).

La herramienta que nos interesa se llama smartctl.

Primero active SMART:

$ smartctl /dev/disk0 -s on

Luego ejecútalo:

$ smartctl /dev/disk0 -x

Este es un extracto de la salida, que proporciona una gran cantidad de información. Los valores para Power_On_Hoursy Power_Cycle_Countdebajo coinciden (una vez convertidos de decimal a hexadecimal) con los que informa la Utilidad de Discos.

smartctl 6.0 2012-10-10 r3643 [x86_64-apple-darwin12.2.0] (local build)
Copyright (C) 2002-12, Bruce Allen, Christian Franke, www.smartmontools.org

=== START OF INFORMATION SECTION ===
Model Family:     JMicron based SSDs
Device Model:     APPLE SSD TS128C
Serial Number:    37AR11AGLTMZ
Firmware Version: CJAA0201
User Capacity:    121,332,826,112 bytes [121 GB]
Sector Size:      512 bytes logical/physical
Rotation Rate:    Solid State Device
Device is:        In smartctl database [for details use: -P show]
ATA Version is:   ATA8-ACS (minor revision not indicated)
SATA Version is:  SATA 2.6, 3.0 Gb/s (current: 3.0 Gb/s)

(...)

SMART Attributes Data Structure revision number: 16
Vendor Specific SMART Attributes with Thresholds:
ID# ATTRIBUTE_NAME          FLAGS    VALUE WORST THRESH FAIL RAW_VALUE
  1 Raw_Read_Error_Rate     -O-R--   099   099   000    -    0
  2 Throughput_Performance  P-S---   100   100   050    -    0
  5 Reallocated_Sector_Ct   PO--C-   100   100   050    -    0
  9 Power_On_Hours          -O--C-   100   100   000    -    3237
 12 Power_Cycle_Count       -O--C-   100   100   000    -    1485
168 SATA_Phy_Error_Count    -O--C-   100   100   000    -    0
170 Bad_Block_Count         PO--C-   100   100   010    -    8 252 82
173 Erase_Count             PO--C-   196   196   100    -    1 136 64
175 Bad_Cluster_Table_Count PO--C-   100   100   010    -    0
192 Unexpect_Power_Loss_Ct  -O--C-   100   100   000    -    14
194 Temperature_Celsius     PO---K   072   053   030    -    28 (Min/Max 14/47)
197 Current_Pending_Sector  -O--C-   100   100   000    -    0
199 UDMA_CRC_Error_Count    -O--C-   100   100   000    -    0
                            ||||||_ K auto-keep
                            |||||__ C event count
                            ||||___ R error rate
                            |||____ S speed/performance
                            ||_____ O updated online
                            |______ P prefailure warning

ATA_READ_LOG_EXT (addr=0x00:0x00, page=0, n=1) failed: 48-bit ATA commands not supported
Read GP Log Directory failed

SMART Log Directory Version 1 [multi-sector log support]
SMART Log at address 0x00 has    1 sectors [Log Directory]
SMART Log at address 0x01 has    1 sectors [Summary SMART error log]
SMART Log at address 0x02 has   51 sectors [Comprehensive SMART error log]
SMART Log at address 0x06 has    1 sectors [SMART self-test log]
SMART Log at address 0x09 has    1 sectors [Selective self-test log]
SMART Log at address 0x80 has   16 sectors [Host vendor specific log]
(...)
SMART Log at address 0x9f has   16 sectors [Host vendor specific log]
SMART Log at address 0xe0 has    1 sectors [SCT Command/Status]
SMART Log at address 0xe1 has    1 sectors [SCT Data Transfer]

SMART Extended Comprehensive Error Log (GP Log 0x03) not supported

SMART Error Log Version: 1
No Errors Logged

SMART Extended Self-test Log (GP Log 0x07) not supported

SMART Self-test log structure revision number 1
Num  Test_Description    Status                  Remaining  LifeTime(hours)  LBA_of_first_error

SMART Selective self-test log data structure revision number 1
 SPAN  MIN_LBA  MAX_LBA  CURRENT_TEST_STATUS
    1        0        0  Not_testing
    2        0        0  Not_testing
    3        0        0  Not_testing
    4        0        0  Not_testing
    5        0        0  Not_testing
Selective self-test flags (0x0):
  After scanning selected spans, do NOT read-scan remainder of disk.
If Selective self-test is pending on power-up, resume after 0 minute delay.

SCT Status Version:                  3
SCT Version (vendor specific):       1 (0x0001)
SCT Support Level:                   0
Device State:                        Active (0)
Current Temperature:                    28 Celsius
Power Cycle Min/Max Temperature:     22/30 Celsius
Lifetime    Min/Max Temperature:     14/47 Celsius
Under/Over Temperature Limit Count:   0/0
SCT Temperature History Version:     2
Temperature Sampling Period:         1 minute
Temperature Logging Interval:        1 minute
Min/Max recommended Temperature:      5/40 Celsius
Min/Max Temperature Limit:            0/70 Celsius
Temperature History Size (Index):    128 (77)

Index    Estimated Time   Temperature Celsius
  78    2012-11-29 19:48    25  ******
 ...    ..(  7 skipped).    ..  ******
  86    2012-11-29 19:56    25  ******
  87    2012-11-29 19:57    26  *******
 ...    ..( 19 skipped).    ..  *******
 107    2012-11-29 20:17    26  *******
 108    2012-11-29 20:18    27  ********
 ...    ..( 16 skipped).    ..  ********
 125    2012-11-29 20:35    27  ********
 126    2012-11-29 20:36    28  *********
 ...    ..(  7 skipped).    ..  *********
   6    2012-11-29 20:44    28  *********
   7    2012-11-29 20:45    29  **********
   8    2012-11-29 20:46    29  **********
   9    2012-11-29 20:47    28  *********
 ...    ..( 67 skipped).    ..  *********
  77    2012-11-29 21:55    28  *********

SMART WRITE LOG does not return COUNT and LBA_LOW register
SCT (Get) Error Recovery Control command failed

Device Statistics (GP Log 0x04) not supported

ATA_READ_LOG_EXT (addr=0x11:0x00, page=0, n=1) failed: 48-bit ATA commands not supported
Read SATA Phy Event Counters failed

Para finalizar, desactive SMART:

$ smartctl /dev/disk0 -s off

¿Qué hay de usar el system_profilercomando incorporado?

system_profiler -listDataTypes
system_profiler SPSerialATADataType
system_profiler -xml SPSerialATADataType

Las Mac más nuevas tienen unidades NVMe y no unidades SATA, por lo que comenzaría con system_profiler SPNVMeDataTypeobtener nombres BSD y otros datos que no son tan detallados como las horas de encendido. El smartctl -a disk0 | grep -I hourscomando de smartmontools es la herramienta de línea de comandos ideal para obtener más detalles sobre el hardware de almacenamiento.

Estos no contienen los datos que busco en mi Air 2011.
Tampoco enumera esos datos system_profiler SPNVMeDataType, pero +1 por la idea de verificar y explicar cómo usar las herramientas.