Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- # -----------------------------------------------------------------
- # Copyright (c) 2021 BestSolution.at EDV Systemhaus GmbH
- # All Rights Reserved.
- #
- # This software is released under the terms of the
- #
- # "GNU Affero General Public License"
- #
- # and may only be distributed and used under the terms of the
- # mentioned license. You should have received a copy of the license
- # along with this software product, if not you can download it from
- # https://www.gnu.org/licenses/agpl-3.0.en.html
- #
- # Author: [email protected]
- # -----------------------------------------------------------------
- #
- # smartctl_cciss.sh
- #
- # Wrapper that converts
- #
- # '$ smartctl [...] /dev/sda' to '$ smartctl -d cciss,0 [...] /dev/sda'
- # '$ smartctl [...] /dev/sdb' to '$ smartctl -d cciss,1 [...] /dev/sdb'
- # '$ smartctl [...] /dev/sdc' to '$ smartctl -d cciss,2 [...] /dev/sdc'
- # ...
- # '$ smartctl [...] /dev/sdp' to '$ smartctl -d cciss,15 [...] /dev/sdp'
- #
- # Per definition (see man smartctl(8)), the maximum number of devices
- # supported by the cciss driver is 15, so the /dev/sdp is the "highest"
- # device accepted (p=15).
- #
- # This is useful for certain HP RAID/HBA controllers that expose the block
- # devices they control as /dev/sdX, but still require '-d cciss,N' to be
- # present when used with smartctl.
- #
- # At the bottom line, this saves you the extra commandline switch plus at
- # the same time allows other tools to read out the SMART values without any
- # further configuration on their side (eg. the proxmox admin interface
- # showing SMART values).
- #
- # To wrap the original smartctl binary using this script, rename the script
- # to /usr/sbin/smartctl.orig and use this script as a replacement, eg like
- # this:
- #
- # $ mv /usr/sbin/smartctl /usr/sbin/smartctl.orig
- # $ cp /path/of/the/downloaded_wrapper/smartctl_cciss.sh /usr/sbin/smartctl
- # $ chmod 755 /usr/sbin/smartctl
- #
- # Later updates of the smartmontools package will probably overwrite the
- # wrapper, so what you can do to prevent this is to make the in place
- # wrapper immutable like this:
- #
- # $ chattr +i /usr/sbin/smartctl
- #
- # ... but this may have some sideffects afterwards (eg. updates might
- # complain that they cannot update the now immutable file).
- #
- # This is a little bit hackish, but it does the job well enough for me :)
- SMARTCTL=/usr/sbin/smartctl.orig
- OPTIONS=("$@")
- # build up map
- char_index=({a..h})
- declare -A num_map
- for((i=0; i < ${#char_index[*]}; ++i)); do
- num_map[${char_index[i]}]=$i
- done
- for((i=1; i<$#; ++i)); do
- device_letter="${OPTIONS[i]#/dev/sd}"
- # only proceed if the given device ends with [a-p]
- if [[ ! -z "${num_map[$device_letter]:-}" ]]; then
- cciss_device="-d cciss,${num_map[$device_letter]}"
- # add the "-d cciss,X" option to the list of options
- OPTIONS=($cciss_device "${OPTIONS[@]}")
- fi
- done
- # build up map
- char_index=({i..p})
- declare -A num_map
- for((i=0; i < ${#char_index[*]}; ++i)); do
- num_map[${char_index[i]}]=$i
- done
- for((i=1; i<$#; ++i)); do
- device_letter="${OPTIONS[i]#/dev/sd}"
- # only proceed if the given device ends with [a-p]
- if [[ ! -z "${num_map[$device_letter]:-}" ]]; then
- cciss_device="-d cciss,${num_map[$device_letter]}"
- # add the "-d cciss,X" option to the list of options
- OPTIONS=($cciss_device "${OPTIONS[@]}")
- fi
- done
- exec $SMARTCTL "${OPTIONS[@]}"
Advertisement
Add Comment
Please, Sign In to add comment