#!/usr/bin/env python3 import subprocess import json from pprint import pprint smart_result = subprocess.run(["sudo", "smartctl", "-Aij", "/dev/sda"], capture_output=True, text=True) smart_result = json.loads(smart_result.stdout) sector_size = smart_result["logical_block_size"] from typing import NamedTuple class RawValue(NamedTuple): value: int string: str class Flags(NamedTuple): value: int string: str prefailure: bool updated_online: bool performance: bool error_rate: bool event_count: bool auto_keep: bool class SmartAttribute(NamedTuple): id: int name: str value: int worst: int thresh: int when_failed: str flags: dict raw: dict attributes = {} for attr in smart_result["ata_smart_attributes"]["table"]: attr_l = SmartAttribute(**attr) attributes[attr_l.id] = attr_l if 241 in attributes: lbas_written = attributes[241].raw["value"] print((lbas_written * sector_size) / 10**12)