#!/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: -a|--array-info ARRAY_INFO Info about arrays and how much free space they provide -l|--ld LD_INFO Info about logical drives -p|--pd PD_INFO Info about physical drives 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 header2 "Controller slot=${CONTROLLER}" ssacli ctrl slot=${CONTROLLER} array all show | sed -e '/^$/d' echo "" done } get_logical_drives() { for CONTROLLER in ${CONTROLLERS}; do header2 "Controller slot=${CONTROLLER}" ssacli ctrl slot=${CONTROLLER} ld all show | sed -e '/^$/d' echo "" done } get_physical_drives() { for CONTROLLER in ${CONTROLLERS}; do header2 "Controller slot=${CONTROLLER}" ssacli ctrl slot=${CONTROLLER} pd all show | sed -e '/^$/d' echo "" done } header1() { cat << HEADER1 ################################################################################ # ${@} ################################################################################ HEADER1 } header2() { cat << HEADER2 # ${@} HEADER2 } ################################################################################ # Argument parser ################################################################################ die() { printf '%s\n' "$1" >&2 exit 1 } while :; do case $1 in -h|-\?|--help) show_help # Display a usage synopsis. exit ;; -a|--array-info) ARRAY_INFO=true ;; -l|--ld) LD_INFO=true ;; -p|--pd) PD_INFO=true ;; --) # 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 [ "${ARRAY_INFO}" == "true" ]; then header1 "Array Infos" get_array_free_space echo "" fi if [ "${LD_INFO}" == "true" ]; then header1 "Logical Drive Infos" get_logical_drives echo "" fi if [ "${PD_INFO}" == "true" ]; then header1 "Physical Drive Infos" get_physical_drives echo "" fi