smartmontools check disk

 

#!/bin/bash

# SMART TEST SCRIPT

 

echo "# Message: Installing smartmontools ..."

sudo apt-get install -y smartmontools > /dev/null && \

echo "# Message: Installed smartmontools."

DEV=`ls /dev/sd?` && \

 

function checkmessage(){

checkfile=$1

errors=0

warning=0

infos=0

# warning=`grep -c "Pre-fail" $checkfile`

# infos=`grep -c "Old_age" $checkfile`

# echo "# Warnings: $warning"

# echo "# infos: $infos"

 

isData=false

# cat $checkfile | while read LINE :while循环内改变无法传递到循环外

while read LINE

do

if [ $isData = "true" ]

then

if [ -n "$LINE" ]

then

ATTRIBUTE=($LINE)

if [ "${ATTRIBUTE[6]}" = "Pre-fail" ]

then

warning=$(( $warning + 1 ))

elif [ "${ATTRIBUTE[6]}" = "Old_age" ]

then

infos=$(( $infos + 1 ))

else

infos=$(( $infos + 1 ))

fi

else

break

fi

 

elif [ "$LINE" = "ID# ATTRIBUTE_NAME FLAG VALUE WORST THRESH TYPE UPDATED WHEN_FAILED RAW_VALUE" ]

then

isData=true

#echo "start"

fi

done < $checkfile

 

#grep "Error Count" $checkfile

errors=`grep "Error Count" $checkfile | tr -cd "[0-9]"`

echo "# Errors: $errors"

echo "# Warnings: $warning"

echo "# Infos: $infos"

#grep "SMART overall-health self-assessment test result:" $checkfile '

result=` grep "SMART overall-health self-assessment test result:" $checkfile | grep -Eo '(FAILED)|(PASSED)' `

echo "# result(PASSED/FAILED) : $result "

}


 

function runtest(){

for SD in $DEV

do

echo

echo "# Message: Detecting $SD ..."

sudo smartctl -s on $SD > /dev/null && \

NUMOLD=`sudo smartctl -l selftest $SD | grep -c 'Completed without error'` && \

echo "# Message: Testing $SD (about 2 minutes) ..."

sudo smartctl -t short $SD > /dev/null && \

while :

do

sleep 1m

ST=`sudo smartctl -l selftest $SD ` && \

NUMNEW=`echo "$ST" | grep -c 'Completed without error'`

echo "$ST" | tail -n 1

#echo "-$NUMNEW -gt $NUMOLD "

if [ "$NUMOLD" = "" ] || [ "$NUMNEW" = "" ] || [ $NUMNEW -gt $NUMOLD ]; then break; fi

done

if [ ! -d "./smartest" ]; then mkdir ./smartest; fi

sudo smartctl -a $SD > ./smartest/${SD:5} && \

sudo smartctl -l error $SD >> ./smartest/${SD:5} && \

echo "# Message: $SD tested."

echo "# Message: Wrote file ./smartest/${SD:5} ."

checkmessage ./smartest/${SD:5}

 

done

}

 

runtest

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值