From 9c0d63603825612b11eabc240681669a9730785f Mon Sep 17 00:00:00 2001 From: John-Mark Gurney Date: Tue, 13 Oct 2020 14:56:52 -0700 Subject: [PATCH] add script for getting disk size and lifetime in a nice table... This depends upon drives being labeled, which I do.. --- diskstat | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100755 diskstat diff --git a/diskstat b/diskstat new file mode 100755 index 0000000..4280963 --- /dev/null +++ b/diskstat @@ -0,0 +1,60 @@ +#!/bin/sh + +# | 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 ' +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 + close(cmd) + + years = sprintf("%.4g", ( hours / 24. / 365 )) + print lblname "\t->\t" devname "\t->\t" disksize[devname] " TB\t->\t" years "\t" model + delete disksize[devname] +} + +$0 ~ "Name" { + state=1 +} + +state == 0 { + ncomp = split($1, comp, "/") + basecomp = comp[ncomp] + if (basecomp !~ "p") { + tb = int($3 / 1000 / 1000 / 1000 / 1000) + if (tb != 0) + disksize[basecomp] = tb + if (tb == 0) + disksize[basecomp] = sprintf("%.2f", int($3 / 1000 / 1000 / 1000) / 1000) + } +} + +state == 1 { + ncomp = split($1, comp, "/") + basecomp = comp[ncomp] + devname = $3 + + if (comp[1] != "label") { + next + } + + printdiskinfo(basecomp, devname) + +} + +END { + for (i in disksize) { + printdiskinfo("xxx", i) + } +} +' - | sort +echo