#!/bin/bash # ### issue TSM server command to some or all TSM servers # # Usage: # $0 [/] line-mode_command # # Within the command string, a literal '$$' is replaced by # the lower-cased SERVERNAME. # ############################################################################### ############# *EXAMPLE* Config: serverid => SERVERNAME (dsm.sys) ########### # # blank-separated ... # A_all="SM1 SM2 SM3 SM4" A_loc1="SM1 SM3" A_loc2="SM2 SM4" A_sm1="SM1" A_sm2="SM2" A_sm3="SM3" A_sm4="SM4" # # comma-separated ... # good_sid="all,loc1,loc2,sm1,sm2,sm3,sm4" # ############################### End Config #################################### options="${1#*/}" sid="${1%%/*}" if [[ "${sid}" != "$1" && -n "${options}" ]]; then options=" ${options}" else options="" fi case "$( echo "@${options}" | tr ' @' '@ ' )" in *@-id*@-pa* | *@-pa*@-id* ) idpwd_in_opt="y" ;; * ) idpwd_in_opt="" ;; esac ##### pat=" ${good_sid//,/ } " # translate commas => space, surround by spaces servers=" " sids="${sid//[^-[:alnum:]]/ }" # translate non-(alphanumerics & "-") => space # this allow for e.g. comma delimiters! # now safe to use w/i command # convenience: is all lower case, so translate upper case #- not on AIX V5: sids="$( echo "@${sids}" | tr '[:upper:]@' '[:lower:] ' )" sids="$( awk -v X="${sids}" 'BEGIN { print tolower(X); exit}' )" for sid in ${sids}; do # if [[ "${sid}" = -* ]]; then neg=1 s="${sid#-}" else neg=0 s="${sid}" fi # if [[ "${pat}" != *\ ${s}\ * ]]; then echo -e "? Bad \$1: ${sid} - supported:\n${good_sid}" 1>&2 exit 99 fi # eval "svs=\${A_${s}}" # if let "${neg}"; then old_servers="${servers}" for sv in ${svs}; do # form (old - new) servers="${servers// ${sv} / }" done # if [[ "${servers}" = "${old_servers}" ]]; then echo "? No match: '-${sid}' vs. '${servers}'" 1>&2 exit 98 fi else svs=" ${svs} " for sv in ${servers}; do # form (new - old) svs="${svs// ${sv} / }" done # servers="${servers}${svs# }" # add (new - old) at end fi done # until here, have 1 space at beginning & end, or are void: " " servers="${servers# }" servers="${servers% }" if [[ -z "${servers}" ]]; then echo "? Void list of servers" 1>&2 exit 97 fi #- not AIX V5: servers="$( echo "@${servers}" | tr '[:upper:]' '[:lower:]' )" #- not AIX V5: servers="${servers#@}" servers="$( awk -v X="${servers}" 'BEGIN { print tolower(X); exit}' )" ##### shift ##### get password (unless spec'd in options) - automagically, or by querying if [[ -z ${idpwd_in_opt} ]]; then mybase="$(basename "$0")" if [[ "${mybase}" = auto* ]]; then # # when this script is called "autoNAME", (try to) ... # ... use default ID and "automatic" password (via "NAME_auto" command) # autopw="$(dirname "$0")/${mybase#auto}_auto" if [[ -x "${autopw}" ]]; then id=${USER} pwd="$(${autopw})" if [[ "${pwd}" != "" ]]; then options="${options} -id=${id} -pa=${pwd}" idpwd_in_opt=auto fi fi fi fi if [[ -z ${idpwd_in_opt} ]]; then echo "" > /dev/tty echo "Default Id: ${USER}" > /dev/tty read -s -r -p "[Id/Password or] Password: " < /dev/tty idpwd="${REPLY}" echo "" > /dev/tty # pwd="${idpwd#*/}" id="${idpwd%%/*}" # if [[ "${pwd}" != "${idpwd}" && -n "${id}" ]]; then echo "" > /dev/tty echo "Using Id = ${id}" > /dev/tty echo "" > /dev/tty else id=${USER} fi else id=XXX pwd=XXX fi ##### for s in ${servers}; do case "${servers}" in *\ *) # multiple servers only - " " in ${servers}" echo "" ( xl="${s} ========================================" xr="======================================== ${s}" echo " ${xl:0:39}${xr:${#xr}-39}" ) ;; esac # echo "$@" | \ sed -e "s/\\\$\\\$/$s/g" | \ dsmadmc -server=${s} -id=${id} -password=${pwd} \ -noconfirm ${options} | \ grep -v $(: "XXX: would -dataonly work here?") \ -e '^IBM Tivoli Storage Manager' \ -e '^Command Line Administrative Interface' \ -e 'Copyright by IBM Corporation' \ -e '^Session established with server' \ -e '^ Server Version .*, Release .*, Level' \ -e '^ Server date/time: .* Last access' | \ { blank=1 # suppress initial blank line(s) while read -r; do #-? [[ "${REPLY}" = ANS1035[EISW]\ * ]] && continue # "no data" [[ "${REPLY}" = ANR1462I\ * ]] && continue # "script successful" [[ "${REPLY}" = ANS8000I\ * ]] && continue # "Server command" [[ "${REPLY}" = ANS8002[EISW]\ * ]] && continue # "Highest rc" if [[ -z "${REPLY}" ]]; then let "blank++ > 0" && continue # suppress multiple blank lines else blank=0 fi echo -E "${REPLY}" done } done exit $? #####