Scripts to report SMART, ZPool and UPS status, HDD/CPU T°, HDD identification and backup the config

Bidule0hm

Server Electronics Sorcerer
Joined
Aug 5, 2013
Messages
3,710
No problem ;)
 

Spearfoot

He of the long foot
Moderator
Joined
May 13, 2015
Messages
2,478
@BiduleOhm: Thanks for your scripts - I use several of them and they're outstanding!

I modified your smart_report.sh script to support the Intel S3700 SSD devices I added to my systems recently. These have longer serial numbers, which required increasing the header block width by 3 (lines 31-35 & 74) and the related printf format spec from 15 to 18 (line 67). I also had to tweak the brand/model detection code in the second 'for drive in $drives' loop (lines 82-86):

Code:
#!/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}
 

ethereal

Guru
Joined
Sep 10, 2012
Messages
762
i will give that a go - i had the same problem with my intel ssd but i couldn't fix it.
 

Bidule0hm

Server Electronics Sorcerer
Joined
Aug 5, 2013
Messages
3,710
You're welcome ;)

And thanks for posting your tweaks for everyone :)
 

ethereal

Guru
Joined
Sep 10, 2012
Messages
762
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
 

Spearfoot

He of the long foot
Moderator
Joined
May 13, 2015
Messages
2,478
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
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.
 

Bidule0hm

Server Electronics Sorcerer
Joined
Aug 5, 2013
Messages
3,710

ethereal

Guru
Joined
Sep 10, 2012
Messages
762
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|
+------+------------------+----+-----+-----+-----+-------+-------+--------+------+----------+------+-------+
 

Bidule0hm

Server Electronics Sorcerer
Joined
Aug 5, 2013
Messages
3,710
Ok, can you post the output (in code tags) of cat -e your_script_name.sh please? (don't forget to delete your email address)
 

Spearfoot

He of the long foot
Moderator
Joined
May 13, 2015
Messages
2,478
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|
+------+------------------+----+-----+-----+-----+-------+-------+--------+------+----------+------+-------+
You're probably viewing it with a proportional font. Try viewing it with a monospace font like Courier and it aligns...

EDIT: Try saving the file with an .html extension and viewing it with your web browser.
 

Bidule0hm

Server Electronics Sorcerer
Joined
Aug 5, 2013
Messages
3,710
There's a pre tag so it should be displayed the right way whatever the police is used.
 

ethereal

Guru
Joined
Sep 10, 2012
Messages
762
Code:
#!/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}
 

Bidule0hm

Server Electronics Sorcerer
Joined
Aug 5, 2013
Messages
3,710
Well, that's cat, not cat -e, but I can see the problem anyway: it's the copy-paste of the script. Did you followed the recommendations I gave in the OP?
 

ethereal

Guru
Joined
Sep 10, 2012
Messages
762
i have your original script - which aligns. and i copied spearfoot's script from his post. that is the one that doesn't work for me.

i used nano and ssh - do you think i should retry this or is it easily editable ?
 

ethereal

Guru
Joined
Sep 10, 2012
Messages
762
i copied and pasted again in ssh - nano full screen but i still have the same problem.
 

Bidule0hm

Server Electronics Sorcerer
Joined
Aug 5, 2013
Messages
3,710
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?
 

Spearfoot

He of the long foot
Moderator
Joined
May 13, 2015
Messages
2,478
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?
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:

http://pastebin.com/NssyGBCL
 

ethereal

Guru
Joined
Sep 10, 2012
Messages
762
that's fixed it. thank you
 

ethereal

Guru
Joined
Sep 10, 2012
Messages
762
one minor quibble - because the ssd does not report it's temperature it's askew.

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  |
+------+------------------+----+-----+-----+-----+-------+-------+--------+------+----------+------+-------+
|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|
+------+------------------+----+-----+-----+-----+-------+-------+--------+------+----------+------+-------+
 

Spearfoot

He of the long foot
Moderator
Joined
May 13, 2015
Messages
2,478
Interesting that it's missing the SSD temperature. All of my SSDs return it. What model of SSD are you using?
 
Top