Last active
August 2, 2023 01:32
-
-
Save likema/d46981e54ba4ca733e194365e9dafd1e to your computer and use it in GitHub Desktop.
Samsung SATA SSD SMART info.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
get() { | |
echo "$SMART_INFO" | awk "/$1/ {print $2}" | |
} | |
device_number() { | |
printf "%u\n" 0x`stat -c $2 $1` | |
} | |
if [ $# -lt 1 ]; then | |
echo "$0 <device>" >&2 | |
exit 1 | |
fi | |
DEVICE=$1 | |
if [ ! -b "$DEVICE" ]; then | |
echo "$DEVICE is not a block device." >&2 | |
exit 1 | |
fi | |
MAJOR=`device_number $DEVICE %t` | |
MINOR=`device_number $DEVICE %T` | |
MODEL=`cat /sys/dev/block/$MAJOR:$MINOR/device/model` | |
if [ "`cat /sys/dev/block/$MAJOR:$MINOR/queue/rotational`" -ne 0 ]; then | |
echo "$DEVICE is not a SSD." >&2 | |
exit 1 | |
fi | |
if ! echo "$MODEL" | grep -qi samsung; then | |
echo "$DEVICE ($MODEL) is not a Samsung SSD" >&2 | |
exit 1 | |
fi | |
SMARTCTL=`which smartctl` | |
BC=`which bc` | |
if [ ! -x "$SMARTCTL" ]; then | |
echo "Please install smartmontools properly." >&2 | |
exit 1 | |
fi | |
if [ ! -x "$BC" ]; then | |
echo "Please install bc properly." >&2 | |
exit 1 | |
fi | |
ON_TIME_TAG="Power_On_Hours" | |
WEAR_COUNT_TAG="Wear_Leveling_Count" | |
LBAS_WRITTEN_TAG="Total_LBAs_Written" | |
LBA_SIZE=512 # Value in bytes | |
BYTES_PER_MB=1048576 | |
BYTES_PER_GB=1073741824 | |
BYTES_PER_TB=1099511627776 | |
SMART_INFO=`sudo $SMARTCTL -A "$DEVICE"` | |
ON_TIME=`get "$ON_TIME_TAG" "\\$10"` | |
WEAR_COUNT=`get "$WEAR_COUNT_TAG" "\\$4" | sed 's/^0*//'` | |
LBAS_WRITTEN=`get "$LBAS_WRITTEN_TAG" "\\$10"` | |
# Convert LBAs -> bytes | |
BYTES_WRITTEN=`expr "$LBAS_WRITTEN" \* "$LBA_SIZE"` | |
MB_WRITTEN=`echo "scale=0; $BYTES_WRITTEN / $BYTES_PER_MB" | $BC` | |
GB_WRITTEN=`echo "scale=2; $BYTES_WRITTEN / $BYTES_PER_GB" | $BC` | |
TB_WRITTEN=`echo "scale=2; $BYTES_WRITTEN / $BYTES_PER_TB" | $BC` | |
WRITE_RATE=`echo "scale=0; $MB_WRITTEN / $ON_TIME" | $BC` | |
cat <<EOF | |
Device : $DEVICE | |
Model : $MODEL | |
On time : $ON_TIME hr | |
Health : $WEAR_COUNT % | |
Write rate : $WRITE_RATE MiB/hr | |
Data written: | |
$MB_WRITTEN MiB | |
$GB_WRITTEN GiB | |
$TB_WRITTEN TiB | |
EOF |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Inspired by
It can not be used for Samsung NVME!