I have a script - run from cron.daily
that gathers SMART stats from two identical SATA SSD's.
However, smartctl -A /dev/sda
sometimes returns the stats for /dev/sdb - and if does so smartctl -A /dev/sdb
returns the stats for /dev/sdb. However, sometimes it gets it right!
The system boots into / on a M2 nvme0n1 with /home on one of the SATA SSD's and all filesystems are mounted via fstab using UUID references.
I have tried inserting random sleep commands - but this makes no difference.
The output of smartctl
doesn't include any notification of what it is the output of - example output:-
smartctl 6.6 2017-11-05 r4594 [x86_64-linux-5.10.0-0.bpo.5-amd64] (local build)
Copyright (C) 2002-17, Bruce Allen, Christian Franke, www.smartmontools.org
=== START OF READ SMART DATA SECTION ===
SMART Attributes Data Structure revision number: 1
Vendor Specific SMART Attributes with Thresholds:
ID# ATTRIBUTE_NAME FLAG VALUE WORST THRESH TYPE UPDATED WHEN_FAILED RAW_VALUE
5 Reallocated_Sector_Ct 0x0033 100 100 010 Pre-fail Always - 0
9 Power_On_Hours 0x0032 099 099 000 Old_age Always - 2396
. . .
uname -a
Linux hal 5.10.0-0.bpo.5-amd64 #1 SMP Debian 5.10.24-1~bpo10+1 (2021-03-29) x86_64 GNU/Linux
Here is the script, which writes all the output as a single CSV line to a log file.
#!/bin/sh
# SMART DISK PROCESSING
# =====================
tmpfile=$(mktemp -q)
today=$(date -u +%d-%m-%Y)
smartctl -A /dev/sdb > $tmpfile
# Output log as a single line - note "Unknown_Attribute" is "POR_Recovery_Count" [unexpected shutdown]
echo -n $today ', ' >> /var/log/disk-monitor.d/sdb-errors.csv
awk 'NR>=8 && NR<=21 {print $1,",",$2,",",$10,",";}' $tmpfile | tr -d '\n' | sed 's/Unknown_Attribute/POR_Recovery_Count/;s/\,$/\n/' >> /var/log/disk-monitor.d/sdb-errors.csv
#------------------------------
smartctl -A /dev/sda > $tmpfile
# Output log as a single line - note "Unknown_Attribute" is "POR_Recovery_Count" [unexpected shutdown]
echo -n $today ', ' >> /var/log/disk-monitor.d/sda-errors.csv
awk 'NR>=8 && NR<=21 {print $1,",",$2,",",$10,",";}' $tmpfile | tr -d '\n' | sed 's/Unknown_Attribute/POR_Recovery_Count/;s/\,$/\n/' >> /var/log/disk-monitor.d/sda-errors.csv
exit 0
/dev/disk/by-id/
or/dev/disk/by-label/
etc.ls /dev/disk/by-id/
shows (amongst other links)ata-Samsung_SSD_870_QVO_1TB_S5SVNG0N955653H
and ata-Samsung_SSD_870_QVO_1TB_S5SVNG0NB22319L