Files
syno_scripts/syno/smart.sh
2018-03-13 08:04:28 +01:00

378 lines
11 KiB
Bash
Executable File
Raw Permalink Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/bin/bash
# http://fr.wikipedia.org/wiki/Self-Monitoring,_Analysis_and_Reporting_Technology
#Attributes names (this is deduced from ID by smartctl and may be incorrect, as it's highly vendor-specific)
#Flag values: if given in POSRCK+ format, the presence of each letter indicates that the flag is on.
#P: pre-failure warning ; O: updated continuously ; S: speed / performance attribute ; R: error rate ; C: event count K: auto-keep ; +: undocumented bits present
#Updated: the attribute is usually updated continuously, or during Offline Data Collection only.
#Type: alarm condition is reached when if normalized value becomes less than or equal to threshold. Type indicates whether it's a signal of drive's pre-failure time or just an old age.
#Raw value: as reported by drive. May or may not be sensible.
#Threshold for normalized value. Normalized value should be greater than threshold
#Worst normalized value recorded for this attribute during the drive's lifetime(with SMART enabled)
#Normalized value (highly vendor-specific; converted from Raw value by the drive's firmware)
#Failed when the normalized value became equal or less than threshold
bold=''
nobold=''
bgblue=''
bgnormal=''
italic=''
noitalic=''
under=''
nounder=''
#modelName=$(echo "$synoSystem" | grep $OID_modelName | cut -d "=" -f2)
# -P showall
#smart2=$(ssh root@192.168.0.8 "smartctl -a /dev/hda -d ata")
#Temp=$(echo "$smart2" | egrep "Model|Temp")
#echo "$Temp"
#WORST (le pire)
#THRESH (battre) threshold (seuil)
#smart3=$(ssh root@192.168.0.8 "find /dev/hd[a-d] -exec /usr/syno/bin/smartctl -iA -d ata {} \;")
#Serial=$(echo "$smart3" | egrep "Serial")
#echo "$Serial"
# fdisk -l ; df -h
# pour les pérfis ide: /dev/hd*
# pour les périferiques sata et usb: /dev/sd*
# fdisk -l | grep "^/dev/"
# df -h | grep "USB"
#sdq: Toshiba 750 Go (volumeUSB2)
#/usr/syno/bin/smartctl -aH -d sat /dev/sdq => OK
#sdr: Toshiba 2 To (volumeUSB1)
#/usr/syno/bin/smartctl -aH -d sat /dev/sdr => OK **
# -d TYPE, --device=TYPE
# Specify device type to one of: ata, scsi, sat[,auto][,N][+TYPE], usbcypress[,X], usbjmicron[,p][,x][,N], usbsunplus, marvell, areca,N/E, 3ware,N, hpt,L/M/N, megaraid,N, cciss,N, auto, test
model=""
serial=""
firmware=""
capacity=""
temperature=""
health=""
smart1=""
smart1v=""
smart1t=""
smart1w=""
smart2=""
smart2v=""
smart2t=""
smart2w=""
smart3=""
smart3v=""
smart3t=""
smart3w=""
smart4=""
smart4v=""
smart4t=""
smart4w=""
smart5=""
smart5v=""
smart5t=""
smart6w=""
smart6=""
smart6v=""
smart6t=""
smart6w=""
smart7=""
smart7v=""
smart7t=""
smart7w=""
smart8=""
smart8v=""
smart8t=""
smart8w=""
smart9=""
smart9v=""
smart9t=""
smart9w=""
smart10=""
smart10v=""
smart10t=""
smart10w=""
smart11=""
smart11v=""
smart11t=""
smart11w=""
smart12=""
smart12v=""
smart12t=""
smart12w=""
smart13=""
smart13v=""
smart13t=""
smart13w=""
smart14=""
smart14v=""
smart14t=""
smart14w=""
smart15=""
smart15v=""
smart15t=""
smart15w=""
i=0
j=0
declare RESULT=()
while read -r LINE; do
RESULT[${#RESULT[@]}]=$LINE
#echo $LINE
_model=$(echo $LINE | grep "Device Model"| cut -d ":" -f2)
if [ -n "$_model" ] ; then model[$i]=$_model ; fi
_serial=$(echo $LINE | grep "Serial Number"| cut -d ":" -f2)
if [ -n "$_serial" ] ; then serial[$i]=$_serial ; fi
_firmware=$(echo $LINE | grep "Firmware Version"| cut -d ":" -f2)
if [ -n "$_firmware" ] ; then firmware[$i]=$_firmware ; fi
# recherche chaine entre [] sed 's/.*\[//;s/\].*//'
_capacity=$(echo $LINE | grep "User Capacity"| cut -d ":" -f2 | sed 's/.*\[//;s/\].*//')
if [ -n "$_capacity" ] ; then capacity[$i]=$_capacity ; fi
_temperature=$(echo $LINE | grep "Temperature_Celsius"| cut -d " " -f10)
if [ -n "$_temperature" ] ; then temperature[$i]=$_temperature ; fi
_health=$(echo $LINE | grep "SMART overall-health"| cut -d ":" -f2 | sed 's/^ *//g')
if [ -n "$_health" ] ; then health[$i]=$_health ; fi
## SMART
_smart1=$(echo $LINE | grep "Raw_Read_Error_Rate") #1
if [ -n "$_smart1" ]
then
# VALUE WORST THRESH (valeur mini failed)
echo $_smart1
smart1[$i]=$(echo $_smart1 | awk '{print $10}')
smart1v[$i]=$(echo $_smart1 | awk '{print $4}')
smart1w[$i]=$(echo $_smart1 | awk '{print $5}')
smart1t[$i]=$(echo $_smart1 | awk '{print $6}')
fi
_smart2=$(echo $LINE | grep "Reallocated_Sector_Ct") #5
if [ -n "$_smart2" ]
then
smart2[$i]=$(echo $_smart2 | awk '{print $10}')
smart2v[$i]=$(echo $_smart2 | awk '{print $4}')
smart2w[$i]=$(echo $_smart2 | awk '{print $5}')
smart2t[$i]=$(echo $_smart2 | awk '{print $6}')
fi
_smart3=$(echo $LINE | grep "Spin_Retry_Count") #10
if [ -n "$_smart3" ]
then
smart3[$i]=$(echo $_smart3 | awk '{print $10}')
smart3v[$i]=$(echo $_smart3 | awk '{print $4}')
smart3w[$i]=$(echo $_smart3 | awk '{print $5}')
smart3t[$i]=$(echo $_smart3 | awk '{print $6}')
fi
_smart4=$(echo $LINE | grep "Command_Timeout") #188
if [ -n "$_smart4" ]
then
smart4[$i]=$(echo $_smart4 | awk '{print $10}')
smart4v[$i]=$(echo $_smart4 | awk '{print $4}')
smart4w[$i]=$(echo $_smart4 | awk '{print $5}')
smart4t[$i]=$(echo $_smart4 | awk '{print $6}')
fi
_smart5=$(echo $LINE | grep "Airflow_Temperature_Cel") #190
if [ -n "$_smart5" ]
then
smart5[$i]=$(echo $_smart5 | awk '{print $10}')
smart5v[$i]=$(echo $_smart5 | awk '{print $4}')
smart5w[$i]=$(echo $_smart5 | awk '{print $5}')
smart5t[$i]=$(echo $_smart5 | awk '{print $6}')
fi
_smart6=$(echo $LINE | grep "Reallocated_Event_Count") #196
if [ -n "$_smart6" ]
then
smart6[$i]=$(echo $_smart6 | awk '{print $10}')
smart6v[$i]=$(echo $_smart6 | awk '{print $4}')
smart6w[$i]=$(echo $_smart6 | awk '{print $5}')
smart6t[$i]=$(echo $_smart6 | awk '{print $6}')
fi
_smart7=$(echo $LINE | grep "Current_Pending_Sector") #197
if [ -n "$_smart7" ]
then
smart7[$i]=$(echo $_smart7 | awk '{print $10}')
smart7v[$i]=$(echo $_smart7 | awk '{print $4}')
smart7w[$i]=$(echo $_smart7 | awk '{print $5}')
smart7t[$i]=$(echo $_smart7 | awk '{print $6}')
fi
_smart8=$(echo $LINE | grep "Offline_Uncorrectable") #198
if [ -n "$_smart8" ]
then
smart8[$i]=$(echo $_smart8 | awk '{print $10}')
smart8v[$i]=$(echo $_smart8 | awk '{print $4}')
smart8w[$i]=$(echo $_smart8 | awk '{print $5}')
smart8t[$i]=$(echo $_smart8 | awk '{print $6}')
fi
_smart9=$(echo $LINE | grep "Soft_Read_Error_Rate") #201
if [ -n "$_smart9" ]
then
smart9[$i]=$(echo $_smart9 | awk '{print $10}')
smart9v[$i]=$(echo $_smart9 | awk '{print $4}')
smart9w[$i]=$(echo $_smart9 | awk '{print $5}')
smart9t[$i]=$(echo $_smart9 | awk '{print $6}')
fi
_smart10=$(echo $LINE | grep "Disk_Shift") #220
if [ -n "$_smart10" ]
then
smart10[$i]=$(echo $_smart10 | awk '{print $10}')
smart10v[$i]=$(echo $_smart10 | awk '{print $4}')
smart10w[$i]=$(echo $_smart10 | awk '{print $5}')
smart10t[$i]=$(echo $_smart10 | awk '{print $6}')
fi
## INFOS
_smart11=$(echo $LINE | grep "Start_Stop_Count") #4
if [ -n "$_smart11" ]
then
smart11[$i]=$(echo $_smart11 | awk '{print $10}')
smart11v[$i]=$(echo $_smart11 | awk '{print $4}')
smart11w[$i]=$(echo $_smart11 | awk '{print $5}')
smart11t[$i]=$(echo $_smart11 | awk '{print $6}')
fi
_smart12=$(echo $LINE | grep "Seek_Error_Rate") #7
if [ -n "$_smart12" ]
then
smart12[$i]=$(echo $_smart12 | awk '{print $10}')
smart12v[$i]=$(echo $_smart12 | awk '{print $4}')
smart12w[$i]=$(echo $_smart12 | awk '{print $5}')
smart12t[$i]=$(echo $_smart12 | awk '{print $6}')
fi
_smart13=$(echo $LINE | grep "Power_On_Hours") #9
if [ -n "$_smart13" ]
then
smart13[$i]=$(echo $_smart13 | awk '{print $10}')
smart13v[$i]=$(echo $_smart13 | awk '{print $4}')
smart13w[$i]=$(echo $_smart13 | awk '{print $5}')
smart13t[$i]=$(echo $_smart13 | awk '{print $6}')
fi
_smart14=$(echo $LINE | grep "Power_Cycle_Count") #12
if [ -n "$_smart14" ]
then
smart14[$i]=$(echo $_smart14 | awk '{print $10}')
smart14v[$i]=$(echo $_smart14 | awk '{print $4}')
smart14w[$i]=$(echo $_smart14 | awk '{print $5}')
smart14t[$i]=$(echo $_smart14 | awk '{print $6}')
fi
_smart15=$(echo $LINE | grep "UDMA_CRC_Error_Count") #199
if [ -n "$_smart15" ]
then
smart15[$i]=$(echo $_smart15 | awk '{print $10}')
smart15v[$i]=$(echo $_smart15 | awk '{print $4}')
smart15w[$i]=$(echo $_smart15 | awk '{print $5}')
smart15t[$i]=$(echo $_smart15 | awk '{print $6}')
fi
if [ -n "$(echo $LINE | grep "Copyright")" ] ; then ((i=i+1)) ; fi
#echo $i
done < <(ssh root@192.168.0.8 "find /dev/sd[a-d,q-r] -exec /usr/syno/bin/smartctl -a -v 9,minutes -d sat {} \;")
#done < <(find /dev/disk0 -exec smartctl -a -v 9,minutes -d sat {} \;)
for((j=1;j<=$i;j++));
do
echo "${bold}Disk $j [${health[j]}]:${nobold}"
echo " Modèle:${model[j]} N° serie:${serial[j]} Firmware:${firmware[j]} Capacité: ${capacity[j]}"
echo " Temp: ${temperature[j]}°C"
echo " ${under}Alarmes:${nounder}"
a=${smart1[j]}
#echo "Raw_Read_Error_Rate: $a"
if [[ -n $a && $a -gt 0 ]]; then echo " Raw_Read_Error_Rate: $a" ; fi
av=${smart1v[j]}
at=${smart1t[j]}
aw=${smart1w[j]}
echo "value: $av tresh: $at worst: $aw"
b=${smart2[j]}
#echo "Reallocated_Sector_Ct: $b"
if [[ -n $b && $b -gt 0 ]]; then echo " Reallocated_Sector_Ct: $b" ; fi
c=${smart3[j]}
#echo "Spin_Retry_Count: $c"
if [[ -n $c && $c -gt 0 ]]; then echo " Spin_Retry_Count: $c" ; fi
d=${smart4[j]}
#echo "Command_Timeout: $d"
if [[ -n $d && $d -gt 0 ]]; then echo " Command_Timeout: $d" ; fi
e=${smart5[j]}
#echo "Airflow_Temperature_Cel: $e"
if [[ -n $e && $e -gt 0 ]]; then echo " Airflow_Temperature_Cel: $e" ; fi
f=${smart6[j]}
#echo "Reallocated_Event_Count: $f"
if [[ -n $f && $f -gt 0 ]]; then echo " Reallocated_Event_Count: $f" ; fi #
g=${smart7[j]}
#echo "Current_Pending_Sector: $g"
if [[ -n $g && $g -gt 0 ]]; then echo " Current_Pending_Sector: $g" ; fi
h=${smart8[j]}
#echo "Offline_Uncorrectable: $h"
if [[ -n $h && $h -gt 0 ]]; then echo " Offline_Uncorrectable: $h" ; fi
k=${smart9[j]}
#echo "Soft_Read_Error_Rate: $k"
if [[ -n $k && $k -gt 0 ]]; then echo " Soft_Read_Error_Rate: $k" ; fi #
l=${smart10[j]}
#echo "Disk_Shift: $l"
if [[ -n $l && $l -gt 0 ]]; then echo " Disk_Shift: $l" ; fi #
echo " ${under}Infos:${nounder}"
m=${smart11[j]}
#echo "Start_Stop_Count: $m"
if [[ -n $m && $m -gt 0 ]]; then echo " Start_Stop_Count: $m" ; fi #
n=${smart12[j]}
#echo "Seek_Error_Rate: $n"
if [[ -n $n && $n -gt 0 ]]; then echo " Seek_Error_Rate: $n" ; fi #
o=${smart13[j]}
#echo "Power_On_Hours: $o"
if [[ -n $o && $o -gt 0 ]]; then echo " Power_On_Hours: $o" ; fi #
p=${smart14[j]}
#echo "Power_Cycle_Count: $p"
if [[ -n $p && $p -gt 0 ]]; then echo " Power_Cycle_Count: $p" ; fi #
q=${smart15[j]}
#echo "UDMA_CRC_Error_Count: $q"
if [[ -n $q && $q -gt 0 ]]; then echo " UDMA_CRC_Error_Count: $q" ; fi #
done
#for hd in /dev/hda*; do
#for hd in /dev/hd[a-z]; do
#for hd in /dev/disk[1-9]; do
#dd=$(ssh root@192.168.0.8 "for hd in /dev/hd[a-d]; do smartctl -A $hd -d ata; done")
#dd=$(ssh root@192.168.0.8 "for i in $(ls /dev/ | grep sd[a-d]\$) ; do /usr/syno/bin/smartctl -A /dev/$i -d ata; done")
#dd=$(ssh root@192.168.0.8 "for i in $(ls /dev/ | grep sd[a-d]\$) ; do /usr/syno/bin/smartctl -A /dev/sda -d ata; done")
#echo "$dd"
#VALUE="_AAAA"
#if [ ${VALUE: 1:3} = "AA" ]; then
#echo "oui"
#else
#echo "non"
#fi