Advertisement
Guest User

Untitled

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