Created
February 24, 2021 11:37
-
-
Save code-inflation/77d242b36754a58af76aacbcbccc4cd4 to your computer and use it in GitHub Desktop.
check disk wear, source: http://www.jdgleaver.co.uk/blog/2014/05/23/samsung_ssds_reading_total_bytes_written_under_linux.html
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
| ####################################### | |
| # Get total data written... # | |
| ####################################### | |
| # Get SMART attributes | |
| SMART_INFO=$(sudo /usr/sbin/smartctl -A "$SSD_DEVICE") | |
| # 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" | |
| 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 "------------------------------" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment