#!/bin/bash if ! [ "${LOGNAME}" == "root" ]; then echo "Please run this script as root or with sudo..." exit 1 fi ################################################################################ # Global variables ################################################################################ ################################################################################ # Functions ################################################################################ show_help() { cat << HELP Script to help around ssacli and automate things... Usage: $1 [OPTION] Mandatory: Optionial: -f|--free-space FREE_SPACE How many free space do the arrays provide HELP exit 0 } get_controllers() { CONTROLLERS=$(ssacli ctrl all show | grep -o 'Slot\ [0-9]\+' | cut -d ' ' -f 2) } get_array_free_space() { for CONTROLLER in ${CONTROLLERS}; do ssacli ctrl slot=${CONTROLLER} array all show | sed -e '/^$/d' done } ################################################################################ # Argument parser ################################################################################ die() { printf '%s\n' "$1" >&2 exit 1 } while :; do case $1 in -h|-\?|--help) show_help # Display a usage synopsis. exit ;; -f|--free-space) FREE_SPACE=true shift ;; --) # End of all options. shift break ;; *) # Default case: No more options, so break out of the loop. break esac shift done ################################################################################ # Main Main Main ################################################################################ if ! get_controllers; then echo "Could not get list of controllers..." exit 1 fi if [ "${FREE_SPACE}" == "true" ]; then get_array_free_space fi