Biduleohm

SMART report (SAS)

Apr 17th, 2015
2,876
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 3.49 KB | None | 0 0
  1. #!/bin/sh
  2.  
  3. ### Parameters ###
  4. logfile="/tmp/smart_report.tmp"
  5. subject="SMART Status Report for FreeNAS"
  6. drives="da0 da1 da2 da3 da4 da5 da6 da7"
  7. tempWarn=40
  8. tempCrit=45
  9. warnSymbol="?"
  10. critSymbol="!"
  11.  
  12. ### Set email headers ###
  13. (
  14.     echo "To: ${email}"
  15.     echo "Subject: ${subject}"
  16.     echo "Content-Type: text/html"
  17.     echo "MIME-Version: 1.0"
  18.     echo -e "\r\n"
  19. ) > ${logfile}
  20.  
  21. ### Set email body ###
  22. echo "<pre style=\"font-size:14px\">" >> ${logfile}
  23.  
  24. ###### summary ######
  25. (
  26.     echo ""
  27.     echo "########## SMART status report summary for all drives ##########"
  28.     echo ""
  29.     echo "+------+---------------+----+-----+------+------+------+------+------+------+"
  30.     echo "|Device|Serial         |Temp|Start|Load  |Defect|Uncorr|Uncorr|Uncorr|Non   |"
  31.     echo "|      |               |    |Stop |Unload|List  |Read  |Write |Verify|Medium|"
  32.     echo "|      |               |    |Count|Count |Elems |Errors|Errors|Errors|Errors|"
  33.     echo "+------+---------------+----+-----+------+------+------+------+------+------+"
  34. ) >> ${logfile}
  35. for drive in $drives
  36. do
  37.     (
  38.         smartctl -a /dev/${drive} | \
  39.         awk -v device=${drive} -v tempWarn=${tempWarn} -v tempCrit=${tempCrit} \
  40.         -v warnSymbol=${warnSymbol} -v critSymbol=${critSymbol} '\
  41.        /Serial number:/{serial=$3} \
  42.        /Current Drive Temperature:/{temp=$4} \
  43.        /start-stop cycles:/{startStop=$4} \
  44.        /load-unload cycles:/{loadUnload=$4} \
  45.        /grown defect list:/{defectList=$6} \
  46.        /read:/{readErrors=$8} \
  47.        /write:/{writeErrors=$8} \
  48.        /verify:/{verifyErrors=$8} \
  49.        /Non-medium error count:/{nonMediumErrors=$4} \
  50.        END {
  51.            if (temp > tempCrit)
  52.                device=device " " critSymbol;
  53.            else if (temp > tempWarn)
  54.                device=device " " warnSymbol;
  55.            printf "|%-6s|%-15s| %s |%5s|%6s|%6s|%6s|%6s|%6s|%6s|\n",
  56.            device, serial, temp, startStop, loadUnload, defectList, \
  57.            readErrors, writeErrors, verifyErrors, nonMediumErrors;
  58.        }'
  59.     ) >> ${logfile}
  60. done
  61. (
  62.     echo "+------+---------------+----+-----+------+------+------+------+------+------+"
  63.     echo ""
  64.     echo ""
  65. ) >> ${logfile}
  66.  
  67. ###### for each drive ######
  68. for drive in $drives
  69. do
  70.     serial=`smartctl -i /dev/${drive} | grep "Serial number" | awk '{print $3}'`
  71.     (
  72.         echo ""
  73.         echo "########## SMART status report for ${drive} drive (${serial}) ##########"
  74.         smartctl -a /dev/${drive}
  75.         echo ""
  76.         echo ""
  77.     ) >> ${logfile}
  78. done
  79. sed -i '' -e '/smartctl 6.3/d' ${logfile}
  80. sed -i '' -e '/Copyright/d' ${logfile}
  81. sed -i '' -e '/Compliance/d' ${logfile}
  82. sed -i '' -e '/LU is resource/d' ${logfile}
  83. sed -i '' -e '/Form Factor/d' ${logfile}
  84. sed -i '' -e '/Logical Unit/d' ${logfile}
  85. sed -i '' -e '/Device type/d' ${logfile}
  86. sed -i '' -e '/Local Time/d' ${logfile}
  87. sed -i '' -e '/SMART support/d' ${logfile}
  88. sed -i '' -e '/Temperature Warning/d' ${logfile}
  89. sed -i '' -e '/=== START OF/d' ${logfile}
  90. sed -i '' -e '/SMART Attributes Data/d' ${logfile}
  91. sed -i '' -e '/Drive Trip/d' ${logfile}
  92. sed -i '' -e '/Manufactured/d' ${logfile}
  93. sed -i '' -e '/Specified cycle count/d' ${logfile}
  94. sed -i '' -e '/Specified load-unload/d' ${logfile}
  95. sed -i '' -e '/Vendor/d' ${logfile}
  96. sed -i '' -e '/Error counter/d' ${logfile}
  97. sed -i '' -e '/SMART Self-test/d' ${logfile}
  98. echo "</pre>" >> ${logfile}
  99.  
  100. ### Send report ###
  101. sendmail -t < ${logfile}
  102. rm ${logfile}
Advertisement
Add Comment
Please, Sign In to add comment