Created
December 29, 2016 00:40
-
-
Save oflow/889934b3878d824a6d35f1fe54dc4089 to your computer and use it in GitHub Desktop.
one-line display `smartctl -H /dev/sdX` and `smartctl -A /dev/sdX`
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
#!/bin/sh | |
# 1 (01) Raw_Read_Error_Rate | |
# 5 (05) Reallocated_Sector_Count | |
# 10 (0A) Spin_Retry_Count | |
# 196 (C4) Reallocated_Event_Count | |
# 199 (C7) UDMA_CRC_Error_Count | |
devices=("sda" "sdb") | |
for dev in "${devices[@]}"; do | |
health=`smartctl -H /dev/$dev | grep "result:" | sed -e "s/^.\+result: \(.\+\)/\1/"` | |
if [ "$health" = "PASSED" ]; then | |
health="\e[0;32m${health}\e[0m" | |
else | |
health="\e[0;31m${health}\e[0m" | |
fi | |
out=`smartctl -A /dev/$dev \ | |
| egrep -e "^ *(1|5|10|196|199) "\ | |
| sed -e "s/^ \+//g" -e "s/ \+/ /g"` | |
#echo "$out" | |
len=`echo "$out" | wc -l` | |
smart= | |
for ((i=0; i<$len; i++)); do | |
line=`expr $i + 1` | |
id=$(printf "%02x" `echo "$out" | sed -n ${line}p | awk '{print $1}'`) | |
value=`echo "$out" | sed -n ${line}p | awk '{print $10}'` | |
if [ "$value" -eq "0" ]; then | |
value="\e[0;32m${value}\e[0m" | |
else | |
value="\e[0;31m${value}\e[0m" | |
fi | |
smart="$smart, ${id^^}: $value" | |
done | |
smart=`echo "$smart" | sed "s/^, //"` | |
echo -e "/dev/$dev S.M.A.R.T [$health] $smart" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment