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.
 
 

75 lines
1.5 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 '"'"'Temperature_Celsius|Device Model:|Power_On_Hours'"'"'"
  10. r = cmd | getline
  11. #print "xfoox" r "x" $0 "xbarx"
  12. model = "unknown"
  13. hours = 0
  14. temp = "unkn"
  15. if (r) {
  16. for (i = 0; i < 3; i++) {
  17. if ($1 == "Device" && $2 == "Model:") {
  18. $1 = ""
  19. $2 = ""
  20. model = sprintf("%-*s", 4*8 - 1, $0)
  21. } else if ($2 == "Temperature_Celsius") {
  22. temp = $10
  23. } else if ($2 == "Power_On_Hours") {
  24. hours = $10
  25. }
  26. r = cmd | getline
  27. }
  28. }
  29. close(cmd)
  30. years = sprintf("%.4g", ( hours / 24. / 365 ))
  31. print lblname "\t->\t" devname "\t->\t" disksize[devname] " TB\t->\t" years "\t" model "\t" temp
  32. delete disksize[devname]
  33. }
  34. $0 ~ "Name" {
  35. state=1
  36. }
  37. state == 0 {
  38. ncomp = split($1, comp, "/")
  39. basecomp = comp[ncomp]
  40. if (basecomp !~ "p") {
  41. tb = int($3 / 1000 / 1000 / 1000 / 1000)
  42. if (tb != 0)
  43. disksize[basecomp] = tb
  44. if (tb == 0)
  45. disksize[basecomp] = sprintf("%.2f", int($3 / 1000 / 1000 / 1000) / 1000)
  46. }
  47. }
  48. state == 1 {
  49. ncomp = split($1, comp, "/")
  50. basecomp = comp[ncomp]
  51. devname = $3
  52. if (comp[1] != "label") {
  53. next
  54. }
  55. printdiskinfo(basecomp, devname)
  56. }
  57. END {
  58. for (i in disksize) {
  59. printdiskinfo("xxx", i)
  60. }
  61. }
  62. ' - | sort
  63. echo