|
- #!/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 $(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'"'"'"
- 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 ))
- 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
|