#!/bin/bash
#
SMARTCTL=`which smartctl 2>/dev/null`
if [ -z $SMARTCTL ] || [ ! -x $SMARTCTL ]; then
echo "It seems you have no smartmontools installed. "
echo "Invoke 'apt install smartmontools' and re-run script"
exit 1
fi
function check {
tmp_parm=`mktemp`
tmp_name=`mktemp`
$SMARTCTL -A $1 | sed -r 's/^\s+//g' > $tmp_parm
$SMARTCTL -i $1| sed -r 's/^\s+//g' > $tmp_name
echo -e $1 - `egrep -m1 "Model " $tmp_name | awk '{$1="";$2=""; print "Model: "$0}'`
echo -e $1 - `egrep -m1 "Device " $tmp_name | awk '{$1="";$2=""; print "Symbol: "$0}'`
echo -e $1 - `egrep -m1 "Serial " $tmp_name | awk '{$1="";$2=""; print "Seria: "$0}'`
for val in 9 5 10 11 171 172 177 181 187 188 196 197 198 199 200 231 ; do
print=`egrep "^$val " $tmp_parm | awk '{ print $2" = "$10 }'`
if [ ! -z "$print" ]; then
echo -n "$1: "
if [[ `echo $print | grep "Power_On_Hours" ` ]]; then
echo -e "\033[36;2m$print\033[0m"
elif [ `echo $print | awk '{ print $3 }'` != 0 ]; then
echo -e "\033[31;2m$print\033[0m"
else
echo -e "\033[32;2m$print\033[0m"
fi
fi
done
echo
rm -f $tmp_parm
rm -r $tmp_name
}
if [ $# -gt 0 ]; then
devices=$@
else
devices=`ls /dev/sd[a-z] 2>/dev/null ; ls /dev/nvme[0-9]n[0-9] 2>/dev/null`
fi
echo
if [ -b /dev/twe0 ]; then
check "-d 3ware,0 /dev/twe0"
check "-d 3ware,1 /dev/twe0"
else
for d in $devices; do
check $d
done
fi
Źródło: