#!/bin/sh
### Parameters ###
logfile="/tmp/smart_report.tmp"
email="my-email@somewhere.tld"
subject="SMART Status Report for My Server"
drives="da2 da3 da4 da5 da6 da7 da8 da9"
tempWarn=40
tempCrit=45
sectorsCrit=10
warnSymbol="?"
critSymbol="!"
### Set email headers ###
(
echo "To: ${email}"
echo "Subject: ${subject}"
echo "Content-Type: text/html"
echo "MIME-Version: 1.0"
echo -e "\r\n"
) > ${logfile}
### Set email body ###
echo "<pre style=\"font-size:14px\">" >> ${logfile}
###### summary ######
(
echo ""
echo "########## SMART status report summary for all drives ##########"
echo ""
echo "+------+------------------+----+-----+-----+-----+-------+-------+--------+------+----------+------+-------+"
echo "|Device|Serial |Temp|Power|Start|Spin |ReAlloc|Current|Offline |Seek |Total |High |Command|"
echo "| | | |On |Stop |Retry|Sectors|Pending|Uncorrec|Errors|Seeks |Fly |Timeout|"
echo "| | | |Hours|Count|Count| |Sectors|Sectors | | |Writes|Count |"
echo "+------+------------------+----+-----+-----+-----+-------+-------+--------+------+----------+------+-------+"
) >> ${logfile}
for drive in $drives
do
(
smartctl -A -i -v 7,hex48 /dev/${drive} | \
awk -v device=${drive} -v tempWarn=${tempWarn} -v tempCrit=${tempCrit} -v sectorsCrit=${sectorsCrit} \
-v warnSymbol=${warnSymbol} -v critSymbol=${critSymbol} '\
/Serial Number:/{serial=$3} \
/Temperature_Celsius/{temp=$10} \
/Power_On_Hours/{onHours=$10} \
/Start_Stop_Count/{startStop=$10} \
/Spin_Retry_Count/{spinRetry=$10} \
/Reallocated_Sector/{reAlloc=$10} \
/Current_Pending_Sector/{pending=$10} \
/Offline_Uncorrectable/{offlineUnc=$10} \
/Seek_Error_Rate/{seekErrors=("0x" substr($10,3,4));totalSeeks=("0x" substr($10,7))} \
/High_Fly_Writes/{hiFlyWr=$10} \
/Command_Timeout/{cmdTimeout=$10} \
END {
if (temp > tempCrit || reAlloc > sectorsCrit || pending > sectorsCrit || offlineUnc > sectorsCrit)
device=device " " critSymbol;
else if (temp > tempWarn || reAlloc > 0 || pending > 0 || offlineUnc > 0)
device=device " " warnSymbol;
seekErrors=sprintf("%d", seekErrors);
totalSeeks=sprintf("%d", totalSeeks);
if (totalSeeks == "0") {
seekErrors="N/A";
totalSeeks="N/A";
}
if (hiFlyWr == "") hiFlyWr="N/A";
if (cmdTimeout == "") cmdTimeout="N/A";
printf "|%-6s|%-18s| %s |%5s|%5s|%5s|%7s|%7s|%8s|%6s|%10s|%6s|%7s|\n",
device, serial, temp, onHours, startStop, spinRetry, reAlloc, pending, offlineUnc, \
seekErrors, totalSeeks, hiFlyWr, cmdTimeout;
}'
) >> ${logfile}
done
(
echo "+------+------------------+----+-----+-----+-----+-------+-------+--------+------+----------+------+-------+"
echo ""
echo ""
) >> ${logfile}
###### for each drive ######
for drive in $drives
do
brand=`smartctl -i /dev/${drive} | grep "Model Family" | awk '{print $3, $4, $5}'`
if [ -z "$brand" ];
then
brand=`smartctl -i /dev/${drive} | grep "Device Model" | awk '{print $3, $4, $5}'`
fi
serial=`smartctl -i /dev/${drive} | grep "Serial Number" | awk '{print $3}'`
(
echo ""
echo "########## SMART status report for ${drive} drive (${brand}: ${serial}) ##########"
smartctl -n never -H -A -l error /dev/${drive}
smartctl -n never -l selftest /dev/${drive} | grep "# 1 \|Num" | cut -c6-
echo ""
echo ""
) >> ${logfile}
done
sed -i '' -e '/smartctl 6.3/d' ${logfile}
sed -i '' -e '/Copyright/d' ${logfile}
sed -i '' -e '/=== START OF READ/d' ${logfile}
sed -i '' -e '/SMART Attributes Data/d' ${logfile}
sed -i '' -e '/Vendor Specific SMART/d' ${logfile}
sed -i '' -e '/SMART Error Log Version/d' ${logfile}
echo "</pre>" >> ${logfile}
### Send report ###
sendmail -t < ${logfile}
rm ${logfile}You have to edit the script and put your desired disks in the 'drives' list on line 7. You'll need to change the email address on line 5 too.the script didn't work for me - i have wd hdds and a single ssd.
it only showed 6 hdds not all 10 or my ssd
+------+------------------+----+-----+-----+-----+-------+-------+--------+------+----------+------+-------+
|Device|Serial |Temp|Power|Start|Spin |ReAlloc|Current|Offline |Seek |Total |High |Command|
| | | |On |Stop |Retry|Sectors|Pending|Uncorrec|Errors|Seeks |Fly |Timeout|
| | | |Hours|Count|Count| |Sectors|Sectors | | |Writes|Count |
+------+------------------+----+-----+-----+-----+-------+-------+--------+------+----------+------+-------+
|da2 |WD-WCC4N0598278 | 28 |17353| 163| 0| 0| 0| 0| N/A| N/A| N/A| N/A|
|da3 |WD-WCC4N0594308 | 28 |17531| 168| 0| 0| 0| 0| N/A| N/A| N/A| N/A|
|da4 |WD-WCC4N0345057 | 31 | 6991| 45| 0| 0| 0| 0| N/A| N/A| N/A| N/A|
|da5 |WD-WMC4N0256459 | 28 | 5798| 45| 0| 0| 0| 0| N/A| N/A| N/A| N/A|
|da6 |WD-WMC4N1274437 | 28 |18582| 173| 0| 0| 0| 0| N/A| N/A| N/A| N/A|
|da7 |WD-WCC4NLATJSJD | 29 |13561| 144| 0| 0| 0| 0| N/A| N/A| N/A| N/A|
|da8 | | | | | | | | | N/A| N/A| N/A| N/A|
|da9 | | | | | | | | | N/A| N/A| N/A| N/A|
+------+------------------+----+-----+-----+-----+-------+-------+--------+------+----------+------+-------+
You're probably viewing it with a proportional font. Try viewing it with a monospace font like Courier and it aligns...i have this -
drives=$(for drive in $(sysctl -n kern.disks); do \
if [ "$(smartctl -i /dev/${drive} | grep "Serial Number" | awk '{print $3}')" ]
then printf ${drive}" "; fi done | awk '{for (i=NF; i!=0 ; i--) print $i }')
but everything is misaligned
HTML:+------+------------------+----+-----+-----+-----+-------+-------+--------+------+----------+------+-------+ |Device|Serial |Temp|Power|Start|Spin |ReAlloc|Current|Offline |Seek |Total |High |Command| | | | |On |Stop |Retry|Sectors|Pending|Uncorrec|Errors|Seeks |Fly |Timeout| | | | |Hours|Count|Count| |Sectors|Sectors | | |Writes|Count | +------+------------------+----+-----+-----+-----+-------+-------+--------+------+----------+------+-------+ |da2 |WD-WCC4N0598278 | 28 |17353| 163| 0| 0| 0| 0| N/A| N/A| N/A| N/A| |da3 |WD-WCC4N0594308 | 28 |17531| 168| 0| 0| 0| 0| N/A| N/A| N/A| N/A| |da4 |WD-WCC4N0345057 | 31 | 6991| 45| 0| 0| 0| 0| N/A| N/A| N/A| N/A| |da5 |WD-WMC4N0256459 | 28 | 5798| 45| 0| 0| 0| 0| N/A| N/A| N/A| N/A| |da6 |WD-WMC4N1274437 | 28 |18582| 173| 0| 0| 0| 0| N/A| N/A| N/A| N/A| |da7 |WD-WCC4NLATJSJD | 29 |13561| 144| 0| 0| 0| 0| N/A| N/A| N/A| N/A| |da8 | | | | | | | | | N/A| N/A| N/A| N/A| |da9 | | | | | | | | | N/A| N/A| N/A| N/A| +------+------------------+----+-----+-----+-----+-------+-------+--------+------+----------+------+-------+
#!/bin/sh
### Parameters ###
logfile="/tmp/smart_report.tmp"
email=""
subject="SMART Status Report for My Server"
drives=$(for drive in $(sysctl -n kern.disks); do \
if [ "$(smartctl -i /dev/${drive} | grep "Serial Number" | awk '{print $3}')" ]
then printf ${drive}" "; fi done | awk '{for (i=NF; i!=0 ; i--) print $i }')
tempWarn=40
tempCrit=45
sectorsCrit=10
warnSymbol="?"
critSymbol="!"
### Set email headers ###
(
echo "To: ${email}"
echo "Subject: ${subject}"
echo "Content-Type: text/html"
echo "MIME-Version: 1.0"
echo -e "\r\n"
) > ${logfile}
### Set email body ###
echo "<pre style=\"font-size:14px\">" >> ${logfile}
###### summary ######
(
echo ""
echo "########## SMART status report summary for all drives ##########"
echo ""
echo "+------+------------------+----+-----+-----+-----+-------+-------+--------+------+----------+------+-------+"
echo "|Device|Serial |Temp|Power|Start|Spin |ReAlloc|Current|Offline |Seek |Total |High |Command|"
echo "| | | |On |Stop |Retry|Sectors|Pending|Uncorrec|Errors|Seeks |Fly |Timeout|"
echo "| | | |Hours|Count|Count| |Sectors|Sectors | | |Writes|Count |"
echo "+------+------------------+----+-----+-----+-----+-------+-------+--------+------+----------+------+-------+"
) >> ${logfile}
for drive in $drives
do
(
smartctl -A -i -v 7,hex48 /dev/${drive} | \
awk -v device=${drive} -v tempWarn=${tempWarn} -v tempCrit=${tempCrit} -v sectorsCrit=${sectorsCrit} \
-v warnSymbol=${warnSymbol} -v critSymbol=${critSymbol} '\
/Serial Number:/{serial=$3} \
/Temperature_Celsius/{temp=$10} \
/Power_On_Hours/{onHours=$10} \
/Start_Stop_Count/{startStop=$10} \
/Spin_Retry_Count/{spinRetry=$10} \
/Reallocated_Sector/{reAlloc=$10} \
/Current_Pending_Sector/{pending=$10} \
/Offline_Uncorrectable/{offlineUnc=$10} \
/Seek_Error_Rate/{seekErrors=("0x" substr($10,3,4));totalSeeks=("0x" substr($10,7))} \
/High_Fly_Writes/{hiFlyWr=$10} \
/Command_Timeout/{cmdTimeout=$10} \
END {
if (temp > tempCrit || reAlloc > sectorsCrit || pending > sectorsCrit || offlineUnc > sectorsCrit)
device=device " " critSymbol;
else if (temp > tempWarn || reAlloc > 0 || pending > 0 || offlineUnc > 0)
device=device " " warnSymbol;
seekErrors=sprintf("%d", seekErrors);
totalSeeks=sprintf("%d", totalSeeks);
if (totalSeeks == "0") {
seekErrors="N/A";
totalSeeks="N/A";
}
if (hiFlyWr == "") hiFlyWr="N/A";
if (cmdTimeout == "") cmdTimeout="N/A";
printf "|%-6s|%-18s| %s |%5s|%5s|%5s|%7s|%7s|%8s|%6s|%10s|%6s|%7s|\n",
device, serial, temp, onHours, startStop, spinRetry, reAlloc, pending, offlineUnc, \
seekErrors, totalSeeks, hiFlyWr, cmdTimeout;
}'
) >> ${logfile}
done
(
echo "+------+------------------+----+-----+-----+-----+-------+-------+--------+------+----------+------+-------+"
echo ""
echo ""
) >> ${logfile}
###### for each drive ######
for drive in $drives
do
brand=`smartctl -i /dev/${drive} | grep "Model Family" | awk '{print $3, $4, $5}'`
if [ -z "$brand" ];
then
brand=`smartctl -i /dev/${drive} | grep "Device Model" | awk '{print $3, $4, $5}'`
fi
serial=`smartctl -i /dev/${drive} | grep "Serial Number" | awk '{print $3}'`
(
echo ""
echo "########## SMART status report for ${drive} drive (${brand}: ${serial}) ##########"
smartctl -n never -H -A -l error /dev/${drive}
smartctl -n never -l selftest /dev/${drive}
echo ""
echo ""
) >> ${logfile}
done
sed -i '' -e '/smartctl 6.3/d' ${logfile}
sed -i '' -e '/Copyright/d' ${logfile}
sed -i '' -e '/=== START OF READ/d' ${logfile}
sed -i '' -e '/SMART Attributes Data/d' ${logfile}
sed -i '' -e '/Vendor Specific SMART/d' ${logfile}
sed -i '' -e '/SMART Error Log Version/d' ${logfile}
echo "</pre>" >> ${logfile}
### Send report ###
sendmail -t < ${logfile}
rm ${logfile}
Certainly! I see what's going on now with the formatting problems from pulling code off the forum. Here's a pastebin link to the revised version. Note that you'll have to add the drive-detection mods:Yep, I can see that the problem is in Spearfoot's post. @Spearfoot can you post the script on pastebin so there's no formatting problem?
+------+------------------+----+-----+-----+-----+-------+-------+--------+------+----------+------+-------+
|Device|Serial |Temp|Power|Start|Spin |ReAlloc|Current|Offline |Seek |Total |High |Command|
| | | |On |Stop |Retry|Sectors|Pending|Uncorrec|Errors|Seeks |Fly |Timeout|
| | | |Hours|Count|Count| |Sectors|Sectors | | |Writes|Count |
+------+------------------+----+-----+-----+-----+-------+-------+--------+------+----------+------+-------+
|ada0 |WD-WCATRA994010 | 33 |26045| 245| 0| 0| 0| 0| N/A| N/A| N/A| N/A|
|ada1 |WD-WCATRA643974 | 33 |29053| 424| 0| 0| 0| 0| N/A| N/A| N/A| N/A|
|ada2 |BTPR251404F5040AGN| |20351| 0| | 0| | | N/A| N/A| N/A| N/A|
|da0 |WD-WMC4N0F63AAE | 28 |10424| 119| 0| 0| 0| 0| N/A| N/A| N/A| N/A|
|da1 |WD-WCC4NNPTEN30 | 28 |13755| 151| 0| 0| 0| 0| N/A| N/A| N/A| N/A|
|da2 |WD-WCC4N0598278 | 29 |17381| 163| 0| 0| 0| 0| N/A| N/A| N/A| N/A|
|da3 |WD-WCC4N0594308 | 29 |17558| 168| 0| 0| 0| 0| N/A| N/A| N/A| N/A|
|da4 |WD-WCC4N0345057 | 31 | 7019| 45| 0| 0| 0| 0| N/A| N/A| N/A| N/A|
|da5 |WD-WMC4N0256459 | 29 | 5825| 45| 0| 0| 0| 0| N/A| N/A| N/A| N/A|
|da6 |WD-WMC4N1274437 | 29 |18610| 173| 0| 0| 0| 0| N/A| N/A| N/A| N/A|
|da7 |WD-WCC4NLATJSJD | 29 |13588| 144| 0| 0| 0| 0| N/A| N/A| N/A| N/A|
+------+------------------+----+-----+-----+-----+-------+-------+--------+------+----------+------+-------+