From 3d4d8eeeef62d563b85043679d8174654f8b2bad Mon Sep 17 00:00:00 2001 From: John-Mark Gurney Date: Wed, 14 Oct 2020 21:36:27 -0700 Subject: [PATCH] minor fix such that if there aren't perms to run smartctl, get sane output instead of random junk.. --- diskstat | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/diskstat b/diskstat index 4280963..5ca23bc 100755 --- a/diskstat +++ b/diskstat @@ -3,18 +3,24 @@ # | egrep $(zpool list -v ztank | grep label | awk 'BEGIN { j="" } { printf "%s%s", j, substr($1, 7, length($1) - 10); j="|" } END { print "" }' ) # state=0 parsing diskinfo # state=1 parsing glabel -(diskinfo /dev/ada*[0-9]; glabel status) | awk -v state=0 ' +(diskinfo $(ls /dev/ada*[0-9] | egrep '^/dev/ada[0-9]+$'); glabel status) | awk -v state=0 ' BEGIN { } function printdiskinfo(lblname, devname) { cmd = "smartctl -a /dev/" devname " | egrep '"'"'Device Model|Power_On_Hours'"'"'" - cmd | getline - $1 = "" - $2 = "" - model = $0 - cmd | getline - hours = $10 + r = cmd | getline + #print "xfoox" r "x" $0 "xbarx" + if (r) { + $1 = "" + $2 = "" + model = $0 + cmd | getline + hours = $10 + } else { + model = "unknown" + hours = 0 + } close(cmd) years = sprintf("%.4g", ( hours / 24. / 365 ))