Advertisement
Spearfoot

Revised version of BiduleOhm's SMART status script

May 4th, 2016
175
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]@[your-domain.tld]"
  6. subject="SMART Status Report"
  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.     echo ""
  31.     echo "+------+------------------+----+-----+-----+-----+-------+-------+--------+------+----------+------+-------+"
  32.     echo "|Device|Serial            |Temp|Power|Start|Spin |ReAlloc|Current|Offline |Seek  |Total     |High  |Command|"
  33.     echo "|      |                  |    |On   |Stop |Retry|Sectors|Pending|Uncorrec|Errors|Seeks     |Fly   |Timeout|"
  34.     echo "|      |                  |    |Hours|Count|Count|       |Sectors|Sectors |      |          |Writes|Count  |"
  35.     echo "+------+------------------+----+-----+-----+-----+-------+-------+--------+------+----------+------+-------+"
  36. ) >> ${logfile}
  37. for drive in $drives
  38. do
  39.     (
  40.         smartctl -A -i -v 7,hex48 /dev/${drive} | \
  41.         awk -v device=${drive} -v tempWarn=${tempWarn} -v tempCrit=${tempCrit} -v sectorsCrit=${sectorsCrit} \
  42.         -v warnSymbol=${warnSymbol} -v critSymbol=${critSymbol} '\
  43.        /Serial Number:/{serial=$3} \
  44.        /Temperature_Celsius/{temp=$10} \
  45.        /Power_On_Hours/{onHours=$10} \
  46.        /Start_Stop_Count/{startStop=$10} \
  47.        /Spin_Retry_Count/{spinRetry=$10} \
  48.        /Reallocated_Sector/{reAlloc=$10} \
  49.        /Current_Pending_Sector/{pending=$10} \
  50.        /Offline_Uncorrectable/{offlineUnc=$10} \
  51.        /Seek_Error_Rate/{seekErrors=("0x" substr($10,3,4));totalSeeks=("0x" substr($10,7))} \
  52.        /High_Fly_Writes/{hiFlyWr=$10} \
  53.        /Command_Timeout/{cmdTimeout=$10} \
  54.        END {
  55.            if (temp > tempCrit || reAlloc > sectorsCrit || pending > sectorsCrit || offlineUnc > sectorsCrit)
  56.                device=device " " critSymbol;
  57.            else if (temp > tempWarn || reAlloc > 0 || pending > 0 || offlineUnc > 0)
  58.                device=device " " warnSymbol;
  59.            seekErrors=sprintf("%d", seekErrors);
  60.            totalSeeks=sprintf("%d", totalSeeks);
  61.            if (totalSeeks == "0") {
  62.                seekErrors="N/A";
  63.                totalSeeks="N/A";
  64.            }
  65.            if (hiFlyWr == "") hiFlyWr="N/A";
  66.            if (cmdTimeout == "") cmdTimeout="N/A";
  67.            printf "|%-6s|%-18s| %s |%5s|%5s|%5s|%7s|%7s|%8s|%6s|%10s|%6s|%7s|\n",
  68.            device, serial, temp, onHours, startStop, spinRetry, reAlloc, pending, offlineUnc, \
  69.            seekErrors, totalSeeks, hiFlyWr, cmdTimeout;
  70.        }'
  71.     ) >> ${logfile}
  72. done
  73. (
  74.     echo "+------+------------------+----+-----+-----+-----+-------+-------+--------+------+----------+------+-------+"
  75.     echo ""
  76.     echo ""
  77. ) >> ${logfile}
  78.  
  79. ###### for each drive ######
  80. for drive in $drives
  81. do
  82.     brand=`smartctl -i /dev/${drive} | grep "Model Family" | awk '{print $3, $4, $5}'`
  83.     if [ -z "$brand" ];
  84.     then
  85.       brand=`smartctl -i /dev/${drive} | grep "Device Model" | awk '{print $3, $4, $5}'`
  86.     fi
  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 -n never -H -A -l error /dev/${drive}
  92.         smartctl -n never -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}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement