What terminal command or program can list an SSD's Power On Hours? I'm looking to script using the unix shell the retrieval of SSD (and HDD) data that disk utility shows in the information window.



I'm immediately interested in the Power On Hours and Power Cycle, but if all the data comes from one data structure or tool, so much the better. The usual tools diskutil info disk0 and ioreg -l are not producing the "of interest" values listed in the screen shot above.

Is this information available from any of the built in OS X terminal tools or do I need to locate an open-source package that makes the same API calls to get this level of detail about a Mac drive?
The command that works for me in 2019 is:

smartctl -a disk0 | grep -i hours


Homebrew install is probably easiest and here are some details on installing and usage of the tool.



smartmontools is an open source package that provides most of the values you are interested in.

If you use Homebrew, install it with:

brew install smartmontools


(In the standard Homebrew installation, commands install to /usr/local/bin.)

Otherwise, download it from https://www.smartmontools.org/wiki/Download and compile it as usual:

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


(Unless otherwise specified as an option to ./configure, smartmontools commands install to /usr/local/sbin, so update the $PATH variable if necessary.)

The tool we are interested in is called smartctl. 

First activate S.M.A.R.T.:

$ smartctl /dev/disk0 -s on


Then run it:

$ smartctl /dev/disk0 -x


This is an excerpt of the output, which provides a wealth of information. The values for Power_On_Hours and Power_Cycle_Count below match (once converted from decimal to hex) the ones Disk Utility reports.

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


To end, deactivate S.M.A.R.T.:

$ smartctl /dev/disk0 -s off