: #!/usr/bin/rksh #!/usr/bin/ksh # # Go grab all the LUN and vhost information for recovery # purposes.. This script runs on VIOS only, must be run # as ROOT (oem_setup_env)... # # This script can be run as padmin by setting the # ownershiphisp file permission to 4555 and creating a symbolic # link ( or copying the script ) to the /home/padmin # direcory. # # Daryl Scott - IBM June 1, 2007 # # Modified by - Gary Galloway - NagraStar June 6, 2007 # Modified to be run as padmin # As root, I put the script in /usr/local/bin # (mode 540, owner.group=padmin.staff) and # created a symbolic like to the /home/padmin # directory. # # ln -s /usr/local/bin/lsvtd /home/padmin/lsvtd # # Modified by - Allan Cano - Itrus Technologied Sep 16, 2010 # Added the -x (first option) to turn on debugging # Added CSV output option with -c # Made the header optional with -b # Added the -u to collect uniq disk identifiers (pvid, wwn, uniq_name) # #--------------------------------------------------------------------# # # # Functions # # # #--------------------------------------------------------------------# Usage() { RC=${1:-"-1"} shift MSG="$@" print " Usage: ${PROG} [-b] [-c] [-u] -b : Brief mode. Don't include header line -c : Print in CSV format -u : Include uniq identifiers (PVID,LUN Id and if run as root uniq_name) ${MSG} " (( RC )) || return 0 exit ${RC} } #--------------------------------------------------------------------# # # # MAIN Main main niam niaM NIAM # # # #--------------------------------------------------------------------# export PATH="/usr/ios/cli:/usr/ios/utils:/usr/ios/lpm/bin:/usr/ios/oem:/usr/ios/ldw/bin:/root/bin:/root/sbin:/home/padmin:$PATH" if [[ '-x' = "$1" ]] then set -x # Turn on debugger typeset -ft $(typeset +f) # Turn on debugger for all functions DFLAG='-x' # Setup a debug flag to pass to script calls shift fi unalias -a # Running as root typeset -i EMC=1 typeset -i ROOT=0 PROG="lsvtd" alias lsdev="ioscli lsdev" alias lsmap="ioscli lsmap" typeset -L8 VHOST typeset -L28 CONN typeset -L15 VTD typeset -L20 LUN typeset -L15 DEV typeset -i BRIEF=0 typeset -i CSV=0 typeset -i UNIQ=0 UNIQ_NAMES="" while getopts :he:cbu FLAG do case "${FLAG}" in h) Usage 1 "This usage and maybe 'man ${PROG}' are help enough." ;; b) BRIEF=1 ;; c) CSV=1 ;; u) UNIQ=1 ;; ?) Usage 2 "Invalid Arguement: ${FLAG}" ;; esac done if (( CSV )) then format='%s,%s,%s,%s,%s,%s' (( UNIQ )) && format=$format',%s,%s,%s' else format='%4s %8s %28s %15s %20s %15s' (( UNIQ )) && format=$format' %16s %32s %32s' fi #### Clear out the options leaving the command in ARG then, shift $(( $OPTIND - 1 )) if (( ! BRIEF )) then (( UNIQ )) && UNIQ_NAMES="'PVID' 'LUN ID' 'U_NAME'" echo 'Lpar' 'Vhost' 'Connection' 'VTD' 'LUN' 'Device' ${UNIQ_NAMES} | awk "{printf \"\n$format\n\",\$1,\$2,\$3,\$4,\$5,\$6,\$7,\$8,\$9}" (( UNIQ )) && UNIQ_NAMES="---------------- -------------------------------- --------------------------------" echo '----' '--------' '----------------------------' '---------------' '--------------------' '---------------' ${UNIQ_NAMES}| \ awk "{printf \"$format\n\",\$1,\$2,\$3,\$4,\$5,\$6,\$7,\$8,\$9}" fi if (( UNIQ )) then lspv > /tmp/lspv.out if id > /dev/null 2> /dev/null then ROOT=1 export PATH="$PATH:/usr/lpp/EMC/Symmetrix/bin:/usr/lpp/Symmetrix/bin" # Find an appropriate inq command or we're donw INQ_CMD="" BIT=$(bootinfo -K) if which inq > /dev/null 2> /dev/null then INQ_CMD=$( which inq ) elif which inq.aix${BIT}_51 > /dev/null 2> /dev/null then INQ_CMD=$( which inq.aix${BIT}_51 ) else EMC=0 fi (( EMC )) && ${INQ_CMD} -nodots | grep hdisk | sed 's:^/dev/r::' > /tmp/inq.out fi fi lsmap -all -fmt , -field SVSA Physloc "Client Partition ID" VTD LUN "Backing device" | while read LINE do print "$LINE" | awk -F, '{printf("%s %s %d",$1,$2,$3)}' | read VHOST CONN LPAR LINE="$(print $LINE | awk -F, '{$1=$2=$3=""}1' | sed -e 's/^ *//' -e 's/ *$//' -e 's/ /,/g' )" while (( ${#LINE} )) do print "$LINE" | awk -F, '{printf("%s %s %s",$1,$2,$3)}' | read VTD LUN DEV LINE="$(print $LINE | awk -F, '{$1=$2=$3=""}1' | sed -e 's/^ *//' -e 's/ *$//' -e 's/ /,/g' )" PVID="" LUNID="" U_NAME="" if (( UNIQ )) && (( $( echo $DEV | awk '{ if( $0 ~ /hdisk|vpath/ ){ print 1 }else { print 0 } }' ) )) then PVID=$( grep -w $DEV /tmp/lspv.out | awk '!/none/{print $2 }' ) if (( ROOT )) then if (( EMC )) then LUNID=$( grep -w $DEV /tmp/inq.out | awk -F: '{print $5}' ) else LUNID="$( lsattr -El $DEV -a ww_name -F value )-$( echo "" | awk '{printf("%d",ID)}' ID=$(lsattr -El $DEV -a lun_id -F value | perl -pe 's/0{12}$//'))" fi U_NAME=$( odmget -q attribute=unique_id CuAt |grep -wp $DEV | awk -F\" '/value/{print $2}' ) fi fi echo | awk "{printf \"$format\n\",LPAR,VHOST,CONN,VTD,LUN,DEV,PVID,LUNID,U_NAME}" LPAR="$LPAR" VHOST="$VHOST" CONN="$CONN" VTD="$VTD" LUN="$LUN" DEV="$DEV" PVID="$PVID" LUNID="$LUNID" U_NAME="$U_NAME" done done exit 0