#!/bin/ksh
# IBM_PROLOG_BEGIN_TAG 
# This is an automatically generated prolog. 
#  
# 61haes_r714 src/43haes/usr/sbin/cluster/cspoc/utilities/cllsconnscsi.sh 1.3 
#  
# Licensed Materials - Property of IBM 
#  
# COPYRIGHT International Business Machines Corp. 1999,2004 
# All Rights Reserved 
#  
# US Government Users Restricted Rights - Use, duplication or 
# disclosure restricted by GSA ADP Schedule Contract with IBM Corp. 
#  
# IBM_PROLOG_END_TAG 
# @(#)33	1.3 src/43haes/usr/sbin/cluster/cspoc/utilities/cllsconnscsi.sh, hacmp.cspoc, 61haes_r714 2/20/04 10:53:13

#############################################################################
#
# Desription
#
#	This is called from SMIT only
#
#	Lists available connections for SCSI disks common to all
#	given nodes.  Checks for accessibility to all nodes.  If all are 
#	accessible, returns list of all available scsi id,lun pairs.
#
# Args
#
#	-k childConnectivity
#	-p nodename-parent pairs
#
# Returns
#
#	0 List of disktypes retrieved from a node
#	1 Error
#	2 Usage error
#
#############################################################################
PATH="$($(dirname ${0})/../utilities/cl_get_path all)"

ARGS=""
#  Check for flags
while [[ $1 = -* ]] ; do
    case $1 in
        -k ) ARGS=$ARGS" -k "$2;shift;;
    esac
    shift
done

PARENT=$@

NODENAMES=""
for COMMAND in $PARENT
do
    NODENAME=`echo $COMMAND | awk -F"," '{ print $1 }'`
    PARENT_NAME=`echo $COMMAND | awk -F"," '{ print $2 }' | awk '{ print $1 }'`
    NODENAMES="$NODENAMES $NODENAME"
    ADDRESS=`clgetaddr $NODENAME 2>/dev/null`
    cl_rsh $ADDRESS "lsconn -p $PARENT_NAME -k scsi" > /tmp/$NODENAME
done

rm /tmp/scsiids 2>/dev/null
touch /tmp/scsiids

FIRST="true"
for NODE in $NODENAMES
do
    if [ "$FIRST" = "true" ]
    then
        cat /tmp/$NODE > /tmp/scsiids
	FIRST="false"
    else
        comm -1 -2 /tmp/$NODE /tmp/scsiids > /tmp/SCSIIDS
	mv /tmp/SCSIIDS /tmp/scsiids
    fi
done

cat /tmp/scsiids

exit 0