Advertisement
Guest User

Untitled

a guest
Jun 14th, 2015
419
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 4.13 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. sectorsCrit=10$
  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. ##########"$
  30.     echo ""$
  31.     echo $
  32. "+------+---------------+----+-----+-----+-----+-------+-------+--------+------+----------+------+-------+"$
  33.     echo "|Device|Serial         |Temp|Power|Start|Spin $
  34. |ReAlloc|Current|Offline |Seek  |Total     |High  |Command|"$
  35.     echo "|      |               |    |On   |Stop $
  36. |Retry|Sectors|Pending|Uncorrec|Errors|Seeks     |Fly   |Timeout|"$
  37.     echo "|      |               |    |Hours|Count|Count|       $
  38. |Sectors|Sectors |      |          |Writes|Count  |"$
  39.     echo $
  40. "+------+---------------+----+-----+-----+-----+-------+-------+--------+------+----------+------+-------+"$
  41. ) >> ${logfile}$
  42. for drive in $drives$
  43. do$
  44.    ($
  45.         smartctl -A -i -v 7,hex48 /dev/${drive} | \$
  46.         awk -v device=${drive} -v tempWarn=${tempWarn} -v $
  47. tempCrit=${tempCrit} -v sectorsCrit=${sectorsCrit} \$
  48.         -v warnSymbol=${warnSymbol} -v critSymbol=${critSymbol} '\$
  49.        /Serial Number:/{serial=$3} \$
  50.        /Temperature_Celsius/{temp=$10} \$
  51.        /Power_On_Hours/{onHours=$10} \$
  52.        /Start_Stop_Count/{startStop=$10} \$
  53.        /Spin_Retry_Count/{spinRetry=$10} \$
  54.        /Reallocated_Sector/{reAlloc=$10} \$
  55.        /Current_Pending_Sector/{pending=$10} \$
  56.        /Offline_Uncorrectable/{offlineUnc=$10} \$
  57.        /Seek_Error_Rate/{seekErrors=("0x" $
  58. substr($10,3,4));totalSeeks=("0x" substr($10,7))} \$
  59.        /High_Fly_Writes/{hiFlyWr=$10} \$
  60.        /Command_Timeout/{cmdTimeout=$10} \$
  61.        END {$
  62.            if (temp > tempCrit || reAlloc > sectorsCrit || pending > $
  63. sectorsCrit || offlineUnc > sectorsCrit)$
  64.                device=device " " critSymbol;$
  65.            else if (temp > tempWarn || reAlloc > 0 || pending > 0 || $
  66. offlineUnc > 0)$
  67.                device=device " " warnSymbol;$
  68.            seekErrors=sprintf("%d", seekErrors);$
  69.            totalSeeks=sprintf("%d", totalSeeks);$
  70.            if (totalSeeks == "0") {$
  71.                seekErrors="N/A";$
  72.                totalSeeks="N/A";$
  73.            }$
  74.            if (hiFlyWr == "") hiFlyWr="N/A";$
  75.            if (cmdTimeout == "") cmdTimeout="N/A";$
  76.            printf "|%-6s|%-15s| %s $
  77. |%5s|%5s|%5s|%7s|%7s|%8s|%6s|%10s|%6s|%7s|\n",$
  78.            device, serial, temp, onHours, startStop, spinRetry, $
  79. reAlloc, pending, offlineUnc, \$
  80.            seekErrors, totalSeeks, hiFlyWr, cmdTimeout;$
  81.        }'$
  82.     ) >> ${logfile}$
  83. done$
  84. ($
  85.     echo $
  86. "+------+---------------+----+-----+-----+-----+-------+-------+--------+------+----------+------+-------+"$
  87.     echo ""$
  88.     echo ""$
  89. ) >> ${logfile}$
  90. $
  91. ###### for each drive ######$
  92. for drive in $drives$
  93. do$
  94.    brand=`smartctl -i /dev/${drive} | grep "Model Family" | awk '{print $
  95. $3, $4, $5}'`$
  96.     serial=`smartctl -i /dev/${drive} | grep "Serial Number" | awk $
  97. '{print $3}'`$
  98.     ($
  99.         echo ""$
  100.         echo "########## SMART status report for ${drive} drive $
  101. (${brand}: ${serial}) ##########"$
  102.         smartctl -n never -H -A -l error /dev/${drive}$
  103.         smartctl -n never -l selftest /dev/${drive} | grep "# 1 \|Num" | $
  104. cut -c6-$
  105.         echo ""$
  106.         echo ""$
  107.     ) >> ${logfile}$
  108. done$
  109. sed -i '' -e '/smartctl 6.3/d' ${logfile}$
  110. sed -i '' -e '/Copyright/d' ${logfile}$
  111. sed -i '' -e '/=== START OF READ/d' ${logfile}$
  112. sed -i '' -e '/SMART Attributes Data/d' ${logfile}$
  113. sed -i '' -e '/Vendor Specific SMART/d' ${logfile}$
  114. sed -i '' -e '/SMART Error Log Version/d' ${logfile}$
  115. echo "</pre>" >> ${logfile}$
  116. $
  117. ### Send report ###$
  118. sendmail -t < ${logfile}$
  119. rm ${logfile}$
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement