Advertisement
Biduleohm

SMART report (SAS)

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