#!/bin/sh
# Copyright (c) 2017-2018 Chuck Tuffli
#
# Permission to use, copy, modify, and distribute this software for any
# purpose with or without fee is hereby granted, provided that the above
# copyright notice and this permission notice appear in all copies.
#
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#
# Sample script to parse output from smart(8) for a SCSI drive
# All positional arguments are passed to smart(8)
# 
# Examples:
#    scsismart da1
#    scsismart -i da1

/usr/local/sbin/smart $* | awk '
/^[A-Z]/
/^2 5/	{print "Write Error counter - total bytes", $3}
/^3 5/	{print "Read Error counter - total bytes", $3}
/^5 5/	{print "Verify Error counter - total bytes", $3}
/^6 0/	{print "Non-Medium Error count", $3}
/^7 0/	{print "Start-Stop"}
/^13 0/	{print "Temperature - current", $3}
/^13 1/	{print "Temperature - reference", $3}
/^14 1/ {print "Manufacture date (yr/wk)", substr($3, 1, 4), substr($3, 5, 2)}
/^14 2/ {print "Accounting date (yr/wk)", substr($3, 1, 4), substr($3, 5, 2)}
/^14 3/ {print "Specified Cycle Count", $3}
/^14 4/ {print "Accumulated Start-Stop cycles", $3}
/^14 5/ {print "Specified Load-Unload Count Over Device Lifetime", $3}
/^14 6/ {print "Accumulated Load-Unload Cycles", $3}
'
