1
momou 2016-03-05 23:30:25 +08:00
去你 ssd 的官网看看
|
2
wwhc 2016-03-06 02:09:59 +08:00
smartmontools
|
3
redsonic 2016-03-06 02:36:47 +08:00
LZ 的是啥 SSD ? linux 下面只有 smartmontools 这一个工具,而且只对像三丧和 intel 这样的大厂支持良好,其余的厂家文档不全或故意不公开接口,第三方工具就没办法了。在 smartmontools 识别你的 SSD 的基础上可以用 smartctl -l devstat /dev/sdx 看到“ Logical Sectors Written ” “ Number of Reallocated Logical Sectors ” “ Number of Reported Uncorrectable Errors ” “ Percentage Used Endurance Indicator ” 等数值,其中最后一个最重要和直观 “ Percentage Used Endurance Indicator ” ,单位是百分比,新的是 0%,该值由主控固件直接算出,应该和 windows 下的官方工具中的剩余寿命同一出处。 重要的事情说三遍: ssd 选 intel , ssd 选 intel , ssd 选 intel 。 intel 不管是硬件还是软件对开发者都很友好。
|
4
zenhand 2016-03-06 06:53:29 +08:00
#!/bin/bash
####################################### # Variables # ####################################### SSD_DEVICE="/dev/sdb" 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=$(echo "你的密码"| sudo -S /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 "------------------------------" |