SMART Status Report - BASH

From Michael's Information Zone
Revision as of 14:55, 7 August 2016 by 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...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

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

t

#!/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