Advertisement
Guest User

Untitled

a guest
Mar 28th, 2020
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 2.27 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. #######################################
  4. # Variables                           #
  5. #######################################
  6.  
  7. SSD_DEVICE="$@"
  8.  
  9. ON_TIME_TAG="Power_On_Hours"
  10. WEAR_COUNT_TAG="Wear_Leveling_Count"
  11. LBAS_WRITTEN_TAG="Total_LBAs_Written"
  12. LBA_SIZE_TAG="Sector Size" # Value in bytes
  13.  
  14. BYTES_PER_MB=1048576
  15. BYTES_PER_GB=1073741824
  16. BYTES_PER_TB=1099511627776
  17.  
  18. #######################################
  19. # Get total data written...           #
  20. #######################################
  21. if [ -z "$@" ]
  22. then
  23. echo "please specify SSD drive by using the following scheme in your shell: './ssd-check.sh /dev/sda'"
  24. echo "substitute sda for your actual SSD drive"
  25.  
  26. else
  27. # Get SMART attributes
  28. SMART_INFO=$(sudo /usr/sbin/smartctl -x "$SSD_DEVICE")
  29.  
  30. # Extract required attributes
  31. ON_TIME=$(echo "$SMART_INFO" | grep "$ON_TIME_TAG" | awk '{print $8}')
  32. WEAR_COUNT=$(echo "$SMART_INFO" | grep "$WEAR_COUNT_TAG" | awk '{print $4}' | sed 's/^0*//')
  33. LBAS_WRITTEN=$(echo "$SMART_INFO" | grep "$LBAS_WRITTEN_TAG" | awk '{print $8}')
  34. LBA_SIZE=$(echo "$SMART_INFO" | grep "$LBA_SIZE_TAG" | awk '{print $3}')
  35.  
  36. # Convert LBAs -> bytes
  37. BYTES_WRITTEN=$(echo "$LBAS_WRITTEN * $LBA_SIZE" | bc)
  38. MB_WRITTEN=$(echo "scale=3; $BYTES_WRITTEN / $BYTES_PER_MB" | bc)
  39. GB_WRITTEN=$(echo "scale=3; $BYTES_WRITTEN / $BYTES_PER_GB" | bc)
  40. TB_WRITTEN=$(echo "scale=3; $BYTES_WRITTEN / $BYTES_PER_TB" | bc)
  41.  
  42. # Output results...
  43. echo "------------------------------"
  44. echo " SSD Status:   $SSD_DEVICE"
  45. echo "------------------------------"
  46. echo " On time:      $(echo $ON_TIME | sed ':a;s/\B[0-9]\{3\}\>/,&/;ta') hr"
  47. echo "------------------------------"
  48. echo " Data written:"
  49. echo "           MB: $(echo $MB_WRITTEN | sed ':a;s/\B[0-9]\{3\}\>/,&/;ta')"
  50. echo "           GB: $(echo $GB_WRITTEN | sed ':a;s/\B[0-9]\{3\}\>/,&/;ta')"
  51. echo "           TB: $(echo $TB_WRITTEN | sed ':a;s/\B[0-9]\{3\}\>/,&/;ta')"
  52. echo "------------------------------"
  53. echo " Mean write rate:"
  54. echo "        MB/hr: $(echo "scale=3; $MB_WRITTEN / $ON_TIME" | bc | sed ':a;s/\B[0-9]\{3\}\>/,&/;ta')"
  55. echo "------------------------------"
  56. if [ -z "$WEAR_COUNT" ]
  57. then
  58.       echo "Drive health feature not supported on this drive"
  59. else
  60.       echo " Drive health: ${WEAR_COUNT} %"
  61. fi
  62. echo "------------------------------"
  63. fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement