Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- #######################################
- # Variables #
- #######################################
- SSD_DEVICE="$@"
- ON_TIME_TAG="Power_On_Hours"
- WEAR_COUNT_TAG="Wear_Leveling_Count"
- LBAS_WRITTEN_TAG="Total_LBAs_Written"
- LBA_SIZE_TAG="Sector Size" # Value in bytes
- BYTES_PER_MB=1048576
- BYTES_PER_GB=1073741824
- BYTES_PER_TB=1099511627776
- #######################################
- # Get total data written... #
- #######################################
- if [ -z "$@" ]
- then
- echo "please specify SSD drive by using the following scheme in your shell: './ssd-check.sh /dev/sda'"
- echo "substitute sda for your actual SSD drive"
- else
- # Get SMART attributes
- SMART_INFO=$(sudo /usr/sbin/smartctl -x "$SSD_DEVICE")
- # Extract required attributes
- ON_TIME=$(echo "$SMART_INFO" | grep "$ON_TIME_TAG" | awk '{print $8}')
- 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 $8}')
- LBA_SIZE=$(echo "$SMART_INFO" | grep "$LBA_SIZE_TAG" | awk '{print $3}')
- # 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"
- 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 "------------------------------"
- if [ -z "$WEAR_COUNT" ]
- then
- echo "Drive health feature not supported on this drive"
- else
- echo " Drive health: ${WEAR_COUNT} %"
- fi
- echo "------------------------------"
- fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement