brick-do.sh shall simplyfy brick actions

This commit is contained in:
Thomas Gebert 2025-10-06 14:25:53 +02:00
parent 6dfffd9f0f
commit 02826df6c6

110
gp-scripts/brick-do.sh Normal file
View File

@ -0,0 +1,110 @@
#!/bin/bash
################################################################################
# Global variables
################################################################################
GLUSTER_CMD="sudo /usr/sbin/gluster"
################################################################################
# Functions
################################################################################
brick_list() {
VOLUME="${1}"
if [ "${VOLUME}" == "" ]; then
echo "No volume given."
return 1
fi
if BRICK_LIST=$(${GLUSTER_CMD} vol info "${VOLUME}" | grep ^Brick[0-9] | cut -d ' ' -f 2); then
return 0
else
return 1
fi
}
execute_command() {
if [ "${COMMAND}" == "" ]; then
echo "No command given."
return 1
fi
for BRICK in ${BRICK_LIST}; do
echo "### ${BRICK} ###"
ssh "${BRICK%%:*}" "${COMMAND} ${BRICK##*:}${BRICK_PATH}"
done
}
show_help() {
cat << HELP
A little helper script to exeucte commands on single bricks.
Usage: $1 [OPTION]
Mandatory:
-c|--COMMAND COMMAND the command to execute
-v|--volume VOLUME the volume of the bricks
Optionial:
-p|--brick-path BRICK_PATH in case the command needs to be run in a
subdirectory of the brick path
HELP
}
################################################################################
# Argument parser
################################################################################
die() {
printf '%s\n' "$1" >&2
exit 1
}
while :; do
case $1 in
-h|-\?|--help)
show_help # Display a usage synopsis.
exit
;;
-c|--COMMAND)
if [ "$2" ]; then
COMMAND=$2
shift
else
die 'ERROR: "-c|--command" requires a non-empty option argument.'
fi
;;
-p|--brick-path)
if [ "$2" ]; then
BRICK_PATH=$2
shift
else
die 'ERROR: "-p|--brick-path" requires a non-empty option argument.'
fi
;;
-v|--volume)
if [ "$2" ]; then
VOLUME=$2
shift
else
die 'ERROR: "-v|--volume" requires a non-empty option argument.'
fi
;;
--) # End of all options.
shift
break
;;
*) # Default case: No more options, so break out of the loop.
break
esac
shift
done
################################################################################
# Main Main Main
################################################################################
brick_list "${VOLUME}"
execute_command "${COMMAND}"