|
- #!/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 '"'"'Temperature_Celsius|Airflow_Temperature_Cel|Device Model:|Power_On_Hours|Current_Pending_Sector|Offline_Uncorrectable'"'"'"
- r = cmd | getline
- #print "xfoox" r "x" $0 "xbarx"
-
- model = "unknown"
- hours = 0
- temp = "unkn"
- if (r) {
- for (i = 0; i < 5; i++) {
- if ($1 == "Device" && $2 == "Model:") {
- $1 = ""
- $2 = ""
- model = sprintf("%-*s", 4*8 - 1, $0)
- } else if ($2 == "Temperature_Celsius" || $2 == "Airflow_Temperature_Cel") {
- temp = $10
- } else if ($2 == "Power_On_Hours") {
- hours = $10
- } else if ($2 == "Current_Pending_Sector") {
- pending = $10
- } else if ($2 == "Offline_Uncorrectable") {
- offline = $10
- }
- r = cmd | getline
- }
- }
- close(cmd)
-
- years = sprintf("%.4g", ( hours / 24. / 365 ))
- print lblname "\t->\t" devname "\t->\t" disksize[devname] " TB\t->\t" years "\t" model "\t" temp "\t" pending "\t" offline
- 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
|