From 02826df6c61416335d8ba1dc597e3f9124e4f352 Mon Sep 17 00:00:00 2001 From: Thomas Gebert Date: Mon, 6 Oct 2025 14:25:53 +0200 Subject: [PATCH] brick-do.sh shall simplyfy brick actions --- gp-scripts/brick-do.sh | 110 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 110 insertions(+) create mode 100644 gp-scripts/brick-do.sh diff --git a/gp-scripts/brick-do.sh b/gp-scripts/brick-do.sh new file mode 100644 index 0000000..5fec8a8 --- /dev/null +++ b/gp-scripts/brick-do.sh @@ -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}" \ No newline at end of file