macdaddybighorn

smartctl wrapper for H240 HBA

May 27th, 2023
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.44 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. # -----------------------------------------------------------------
  4. # Copyright (c) 2021 BestSolution.at EDV Systemhaus GmbH
  5. # All Rights Reserved.
  6. #
  7. # This software is released under the terms of the
  8. #
  9. # "GNU Affero General Public License"
  10. #
  11. # and may only be distributed and used under the terms of the
  12. # mentioned license. You should have received a copy of the license
  13. # along with this software product, if not you can download it from
  14. # https://www.gnu.org/licenses/agpl-3.0.en.html
  15. #
  16. # -----------------------------------------------------------------
  17. #
  18. # smartctl_cciss.sh
  19. #
  20. # Wrapper that converts
  21. #
  22. # '$ smartctl [...] /dev/sda' to '$ smartctl -d cciss,0 [...] /dev/sda'
  23. # '$ smartctl [...] /dev/sdb' to '$ smartctl -d cciss,1 [...] /dev/sdb'
  24. # '$ smartctl [...] /dev/sdc' to '$ smartctl -d cciss,2 [...] /dev/sdc'
  25. # ...
  26. # '$ smartctl [...] /dev/sdp' to '$ smartctl -d cciss,15 [...] /dev/sdp'
  27. #
  28. # Per definition (see man smartctl(8)), the maximum number of devices
  29. # supported by the cciss driver is 15, so the /dev/sdp is the "highest"
  30. # device accepted (p=15).
  31. #
  32. # This is useful for certain HP RAID/HBA controllers that expose the block
  33. # devices they control as /dev/sdX, but still require '-d cciss,N' to be
  34. # present when used with smartctl.
  35. #
  36. # At the bottom line, this saves you the extra commandline switch plus at
  37. # the same time allows other tools to read out the SMART values without any
  38. # further configuration on their side (eg. the proxmox admin interface
  39. # showing SMART values).
  40. #
  41. # To wrap the original smartctl binary using this script, rename the script
  42. # to /usr/sbin/smartctl.orig and use this script as a replacement, eg like
  43. # this:
  44. #
  45. # $ mv /usr/sbin/smartctl /usr/sbin/smartctl.orig
  46. # $ cp /path/of/the/downloaded_wrapper/smartctl_cciss.sh /usr/sbin/smartctl
  47. # $ chmod 755 /usr/sbin/smartctl
  48. #
  49. # Later updates of the smartmontools package will probably overwrite the
  50. # wrapper, so what you can do to prevent this is to make the in place
  51. # wrapper immutable like this:
  52. #
  53. # $ chattr +i /usr/sbin/smartctl
  54. #
  55. # ... but this may have some sideffects afterwards (eg. updates might
  56. # complain that they cannot update the now immutable file).
  57. #
  58. # This is a little bit hackish, but it does the job well enough for me :)
  59.  
  60. SMARTCTL=/usr/sbin/smartctl.orig
  61. OPTIONS=("$@")
  62.  
  63. # build up map
  64. char_index=({a..h})
  65. declare -A num_map
  66. for((i=0; i < ${#char_index[*]}; ++i)); do
  67. num_map[${char_index[i]}]=$i
  68. done
  69.  
  70. for((i=1; i<$#; ++i)); do
  71. device_letter="${OPTIONS[i]#/dev/sd}"
  72. # only proceed if the given device ends with [a-p]
  73. if [[ ! -z "${num_map[$device_letter]:-}" ]]; then
  74. cciss_device="-d cciss,${num_map[$device_letter]}"
  75. # add the "-d cciss,X" option to the list of options
  76. OPTIONS=($cciss_device "${OPTIONS[@]}")
  77. fi
  78. done
  79.  
  80. # build up map
  81. char_index=({i..p})
  82. declare -A num_map
  83. for((i=0; i < ${#char_index[*]}; ++i)); do
  84. num_map[${char_index[i]}]=$i
  85. done
  86.  
  87. for((i=1; i<$#; ++i)); do
  88. device_letter="${OPTIONS[i]#/dev/sd}"
  89. # only proceed if the given device ends with [a-p]
  90. if [[ ! -z "${num_map[$device_letter]:-}" ]]; then
  91. cciss_device="-d cciss,${num_map[$device_letter]}"
  92. # add the "-d cciss,X" option to the list of options
  93. OPTIONS=($cciss_device "${OPTIONS[@]}")
  94. fi
  95. done
  96.  
  97. exec $SMARTCTL "${OPTIONS[@]}"
Advertisement
Add Comment
Please, Sign In to add comment