1
0
mirror of https://github.com/artizirk/dotfiles.git synced 2024-12-01 19:31:00 +02:00
dotfiles/.bin/ssd_life

59 lines
2.3 KiB
Plaintext
Raw Normal View History

2020-04-14 17:42:34 +03:00
#!/bin/bash
2021-05-30 10:42:46 +03:00
# From https://scottlinux.com/2014/07/15/determine-remaining-ssd-life-in-linux/
2021-05-30 11:04:52 +03:00
# Or https://askubuntu.com/questions/865792/how-can-i-monitor-the-tbw-on-my-samsung-ssd
2020-04-14 17:42:34 +03:00
#######################################
# Variables #
#######################################
2021-05-30 11:04:52 +03:00
SSD_DEVICE=${1:-"/dev/sda"}
2020-04-14 17:42:34 +03:00
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
#######################################
# Get total data written... #
#######################################
# Get SMART attributes
SMART_INFO=$(sudo /usr/sbin/smartctl -A "$SSD_DEVICE")
2021-05-30 11:04:52 +03:00
DISK_INFO=$(sudo /usr/sbin/smartctl -i "$SSD_DEVICE")
DISK_MODEL=$(echo "$DISK_INFO" | awk 'BEGIN { FS = " *: *" } ; /Device Model/ { print $2 }')
DISK_SERIAL=$(echo "$DISK_INFO" | awk 'BEGIN { FS = " *: *" } ; /Serial Number/ { print $2 }')
2020-04-14 17:42:34 +03:00
# Extract required attributes
ON_TIME=$(echo "$SMART_INFO" | grep "$ON_TIME_TAG" | awk '{print $10}')
WEAR_COUNT=$(echo "$SMART_INFO" | grep "$WEAR_COUNT_TAG" | awk '{print $4}' | sed 's/^0*//')
LBAS_WRITTEN=$(echo "$SMART_INFO" | grep "$LBAS_WRITTEN_TAG" | awk '{print $10}')
# Convert LBAs -> bytes
BYTES_WRITTEN=$(echo "$LBAS_WRITTEN * $LBA_SIZE" | bc)
MB_WRITTEN=$(echo "scale=3; $BYTES_WRITTEN / $BYTES_PER_MB" | bc)
GB_WRITTEN=$(echo "scale=3; $BYTES_WRITTEN / $BYTES_PER_GB" | bc)
TB_WRITTEN=$(echo "scale=3; $BYTES_WRITTEN / $BYTES_PER_TB" | bc)
# Output results...
echo "------------------------------"
echo " SSD Status: $SSD_DEVICE"
2021-05-30 11:04:52 +03:00
echo " SSD Model: $DISK_MODEL"
echo " SSD Serial: $DISK_SERIAL"
2020-04-14 17:42:34 +03:00
echo "------------------------------"
echo " On time: $(echo $ON_TIME | sed ':a;s/\B[0-9]\{3\}\>/,&/;ta') hr"
echo "------------------------------"
echo " Data written:"
echo " MB: $(echo $MB_WRITTEN | sed ':a;s/\B[0-9]\{3\}\>/,&/;ta')"
echo " GB: $(echo $GB_WRITTEN | sed ':a;s/\B[0-9]\{3\}\>/,&/;ta')"
echo " TB: $(echo $TB_WRITTEN | sed ':a;s/\B[0-9]\{3\}\>/,&/;ta')"
echo "------------------------------"
echo " Mean write rate:"
echo " MB/hr: $(echo "scale=3; $MB_WRITTEN / $ON_TIME" | bc | sed ':a;s/\B[0-9]\{3\}\>/,&/;ta')"
echo "------------------------------"
echo " Drive health: ${WEAR_COUNT} %"
echo "------------------------------"