Biduleohm

SMART report (SATA)

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

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×