brick-do.sh shall simplyfy brick actions #14
110
gp-scripts/brick-do.sh
Normal file
110
gp-scripts/brick-do.sh
Normal 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}"
|
||||
Loading…
Reference in New Issue
Block a user