Browse Source

minor fix such that if there aren't perms to run smartctl, get

sane output instead of random junk..
main
John-Mark Gurney 4 years ago
parent
commit
3d4d8eeeef
1 changed files with 13 additions and 7 deletions
  1. +13
    -7
      diskstat

+ 13
- 7
diskstat View File

@@ -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 "" }' ) # | 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=0 parsing diskinfo
# state=1 parsing glabel # 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 { BEGIN {
} }


function printdiskinfo(lblname, devname) { function printdiskinfo(lblname, devname) {
cmd = "smartctl -a /dev/" devname " | egrep '"'"'Device Model|Power_On_Hours'"'"'" 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) close(cmd)


years = sprintf("%.4g", ( hours / 24. / 365 )) years = sprintf("%.4g", ( hours / 24. / 365 ))


Loading…
Cancel
Save