Set of scripts used for various projects.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

67 lines
1.3 KiB

  1. #!/bin/sh
  2. # | egrep $(zpool list -v ztank | grep label | awk 'BEGIN { j="" } { printf "%s%s", j, substr($1, 7, length($1) - 10); j="|" } END { print "" }' )
  3. # state=0 parsing diskinfo
  4. # state=1 parsing glabel
  5. (diskinfo $(ls /dev/ada*[0-9] | egrep '^/dev/ada[0-9]+$'); glabel status) | awk -v state=0 '
  6. BEGIN {
  7. }
  8. function printdiskinfo(lblname, devname) {
  9. cmd = "smartctl -a /dev/" devname " | egrep '"'"'Device Model|Power_On_Hours'"'"'"
  10. r = cmd | getline
  11. #print "xfoox" r "x" $0 "xbarx"
  12. if (r) {
  13. $1 = ""
  14. $2 = ""
  15. model = $0
  16. cmd | getline
  17. hours = $10
  18. } else {
  19. model = "unknown"
  20. hours = 0
  21. }
  22. close(cmd)
  23. years = sprintf("%.4g", ( hours / 24. / 365 ))
  24. print lblname "\t->\t" devname "\t->\t" disksize[devname] " TB\t->\t" years "\t" model
  25. delete disksize[devname]
  26. }
  27. $0 ~ "Name" {
  28. state=1
  29. }
  30. state == 0 {
  31. ncomp = split($1, comp, "/")
  32. basecomp = comp[ncomp]
  33. if (basecomp !~ "p") {
  34. tb = int($3 / 1000 / 1000 / 1000 / 1000)
  35. if (tb != 0)
  36. disksize[basecomp] = tb
  37. if (tb == 0)
  38. disksize[basecomp] = sprintf("%.2f", int($3 / 1000 / 1000 / 1000) / 1000)
  39. }
  40. }
  41. state == 1 {
  42. ncomp = split($1, comp, "/")
  43. basecomp = comp[ncomp]
  44. devname = $3
  45. if (comp[1] != "label") {
  46. next
  47. }
  48. printdiskinfo(basecomp, devname)
  49. }
  50. END {
  51. for (i in disksize) {
  52. printdiskinfo("xxx", i)
  53. }
  54. }
  55. ' - | sort
  56. echo