Difference between revisions of "SMART Status Report - BASH"
Jump to navigation
Jump to search
Michael.mast (talk | contribs) (Created page with "As I work more and more with direct disk access filesystems (ie ZFS) I find a need to keep tabs on my disks. The following was created as a side project to keep an eye on my h...") |
Michael.mast (talk | contribs) |
||
Line 1: | Line 1: | ||
As I work more and more with direct disk access filesystems (ie ZFS) I find a need to keep tabs on my disks. The following was created as a side project to keep an eye on my home server that have hard to reach drives, so knowing when one is about to fail is important. | As I work more and more with direct disk access filesystems (ie ZFS) I find a need to keep tabs on my disks. The following was created as a side project to keep an eye on my home server that have hard to reach drives, so knowing when one is about to fail is important. | ||
<br> | <br> | ||
+ | ==First Version== | ||
The first version prints out in the terminal | The first version prints out in the terminal | ||
*The device | *The device | ||
Line 6: | Line 7: | ||
*and all previous test results. | *and all previous test results. | ||
Frankly this is not very elegant and is not presented in a clean manner but it is a start. | Frankly this is not very elegant and is not presented in a clean manner but it is a start. | ||
− | + | <pre> | |
#!/bin/bash | #!/bin/bash | ||
##Create list of all possible sata block devices | ##Create list of all possible sata block devices | ||
Line 35: | Line 36: | ||
cat /tmp/drivereport | cat /tmp/drivereport | ||
rm -f /tmp/drivereport | rm -f /tmp/drivereport | ||
+ | </pre> | ||
+ | ==Second Version== | ||
+ | This one prints out the health general health assessment on the terminal as either passed or failed, but then creates a more "detailed" report in /var/log. | ||
+ | <pre> | ||
+ | #!/bin/bash | ||
+ | ##Create list of all possible sata block devices | ||
+ | for i in {a..z} | ||
+ | do | ||
+ | echo sd$i >> /tmp/drivelist | ||
+ | done | ||
+ | ##Loop through the list and check to see if the drive exists, then record the SMART status as well as the | ||
+ | ##records of all tests run. Also prints out a general status of the drives | ||
+ | ##onto the terminal. | ||
+ | while read line | ||
+ | do | ||
+ | smartctl -H /dev/$line > /tmp/asdasd | ||
+ | if grep -q "No such device" /tmp/asdasd; then | ||
+ | rm -f /tmp/asdasd | ||
+ | else | ||
+ | rm -f /tmp/asdasd | ||
+ | echo "*****************************************************************************" >> /tmp/drivereport | ||
+ | echo /dev/$line >> /tmp/drivereport | ||
+ | smartctl -H /dev/$line >> /tmp/drivereport | ||
+ | smartctl -H /dev/$line > /tmp/assessmentstatus | ||
+ | if grep -q -i passed /tmp/assessmentstatus; then | ||
+ | echo "$line : GOOD" | ||
+ | elif grep -q -i failed /tmp/assessmentstatus; then | ||
+ | echo "$line : $(tput setaf 1)REPLACE$(tput sgr 0)" | ||
+ | else | ||
+ | echo "$line : UNKOWN STATUS" | ||
+ | fi | ||
+ | rm -f /tmp/assessmentstatus | ||
+ | echo "Last Smart Test Results" >> /tmp/drivereport | ||
+ | smartctl -a /dev/$line > /tmp/smartoutput | ||
+ | grep offline /tmp/smartoutput >> /tmp/drivereport | ||
+ | rm -f /tmp/smartoutput | ||
+ | fi | ||
+ | done < /tmp/drivelist | ||
+ | rm -f /tmp/drivelist | ||
+ | ##Create the "Full log" and place it in /var/log/ with today's date. | ||
+ | now1=$(date +%m-%d-%y) | ||
+ | cp /tmp/drivereport /var/log/smart_$now1 | ||
+ | rm -f /tmp/drivereport | ||
+ | echo "Full report available in /var/log/smart_$now1" | ||
</pre> | </pre> |
Revision as of 15:49, 7 August 2016
As I work more and more with direct disk access filesystems (ie ZFS) I find a need to keep tabs on my disks. The following was created as a side project to keep an eye on my home server that have hard to reach drives, so knowing when one is about to fail is important.
First Version
The first version prints out in the terminal
- The device
- Whether or not it has passed overall SMART health assessments
- and all previous test results.
Frankly this is not very elegant and is not presented in a clean manner but it is a start.
#!/bin/bash ##Create list of all possible sata block devices for i in {a..z} do echo sd$i >> /tmp/drivelist done ##Loop through the list and check to see if the drive exists, then record the SMART status as well as the ##records of all tests run while read line do smartctl -H /dev/$line > /tmp/asdasd if grep -q "No such device" /tmp/asdasd; then rm -f /tmp/asdasd else rm -f /tmp/asdasd echo "*****************************************************************************" >> /tmp/drivereport echo /dev/$line >> /tmp/drivereport smartctl -H /dev/$line >> /tmp/drivereport echo "Last Smart Test Results" >> /tmp/drivereport smartctl -a /dev/$line > /tmp/smartoutput grep offline /tmp/smartoutput >> /tmp/drivereport rm -f /tmp/smartoutput fi done < /tmp/drivelist rm -f /tmp/drivelist clear cat /tmp/drivereport rm -f /tmp/drivereport
Second Version
This one prints out the health general health assessment on the terminal as either passed or failed, but then creates a more "detailed" report in /var/log.
#!/bin/bash ##Create list of all possible sata block devices for i in {a..z} do echo sd$i >> /tmp/drivelist done ##Loop through the list and check to see if the drive exists, then record the SMART status as well as the ##records of all tests run. Also prints out a general status of the drives ##onto the terminal. while read line do smartctl -H /dev/$line > /tmp/asdasd if grep -q "No such device" /tmp/asdasd; then rm -f /tmp/asdasd else rm -f /tmp/asdasd echo "*****************************************************************************" >> /tmp/drivereport echo /dev/$line >> /tmp/drivereport smartctl -H /dev/$line >> /tmp/drivereport smartctl -H /dev/$line > /tmp/assessmentstatus if grep -q -i passed /tmp/assessmentstatus; then echo "$line : GOOD" elif grep -q -i failed /tmp/assessmentstatus; then echo "$line : $(tput setaf 1)REPLACE$(tput sgr 0)" else echo "$line : UNKOWN STATUS" fi rm -f /tmp/assessmentstatus echo "Last Smart Test Results" >> /tmp/drivereport smartctl -a /dev/$line > /tmp/smartoutput grep offline /tmp/smartoutput >> /tmp/drivereport rm -f /tmp/smartoutput fi done < /tmp/drivelist rm -f /tmp/drivelist ##Create the "Full log" and place it in /var/log/ with today's date. now1=$(date +%m-%d-%y) cp /tmp/drivereport /var/log/smart_$now1 rm -f /tmp/drivereport echo "Full report available in /var/log/smart_$now1"