#!/bin/ksh93
# IBM_PROLOG_BEGIN_TAG 
# This is an automatically generated prolog. 
#  
# 61haes_r714 src/43haes/usr/sbin/cluster/cspoc/utilities/cli_on_node.sh 1.4 
#  
# Licensed Materials - Property of IBM 
#  
# COPYRIGHT International Business Machines Corp. 2003,2005 
# 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 
# @(#)32        1.4  src/43haes/usr/sbin/cluster/cspoc/utilities/cli_on_node.sh, hacmp.cspoc, 61haes_r714 9/3/05 15:24:10

###############################################################################
#
#   COMPONENT_NAME: CSPOC Command Line Interface
#
# Name:
#   cli_on_node
#
# Description:
#   Use C-SPOC to run the cl_on_node command with the given parameters
#
#   Runs a given command on either an explicitly specified node, or on the
#   cluster node that owns a specified volume group or resource group.
#
# Arguments:
#       [-V <volume group> | -R <resource group | -N <node> ]
#       'command string'
#
#   Setting the environment variable _DEBUG to 1 -> 9 turns on levels of
#   C-SPOC debugging
#
# Return Values:
#   As set by cl_on_node
#
# Notes:
#   The '-f' flag is passed on cl_on_node to surpress unnecessary checking.
#   As a consequence, the operation will proceed even if not all nodes are
#   accessable
#
#  Questions?  Comments?  Expressions of Astonishment?	mailto:hafeedbk@us.ibm.com
#
################################################################################


typeset DEBUG

#
#   Variables needed by cl_on_node
#	_CSPOC_MODE - working with shared (as opposed to concurrent) volume
#			groups
#	_CSPOC_CALLED_FROM_SMIT - can skip checks on input
#
export _CSPOC_MODE="shared"
export _CSPOC_CALLED_FROM_SMIT="true"

#   Ensure correct invocation
flag=$1 ; shift
operand=$1 ; shift
if [[ -z $flag || -z $operand || -z $@ ]] ||
   [[ $flag != '-V' && $flag != '-R' && $flag != '-N' ]] ; then
   USAGE=$(dspmsg -s 9 cspoc.cat 555 'Usage: cli_on_node [-V <volume group> |-R <resource group> | -N <node> ] command')
   print $USAGE
   exit 1
fi

#
#   If a _DEBUG value has been set, pass it through
#
if [[ -n $_DEBUG ]] ; then

    #
    #	The debug level is a number, 1 through 9.  Those values are passed
    #	through.  Anything else is turned into '1'
    #
    integer dbg_level=$_DEBUG
    if (( $dbg_level < 10 && $dbg_level >= 1 )) ; then
	DEBUG="-d $_DEBUG"
    else
	DEBUG="-d 1"
    fi
fi

#
#   Construct the node list.  
#
if [[ $flag == '-N' ]] ; then
    #
    #	If an explict node has been specified, pass it through.
    #
    export _NODE_LIST=$operand
    flag=""
    operand=""
else
    #
    #   If "-V" or "-R" has been specified, then pass as node list all the
    #   nodes in the cluster.  cl_on_node will search them all for the owner of
    #   the volume group/resource group.
    #
    export _NODE_LIST=$(IFS=, set -- $(odmget -q "object = VERBOSE_LOGGING" HACMPnode | \
		        grep 'name =' | cut -f2 -d'"') ; print "$*")
fi

#
#   Invoke the cspoc code to run the command on the specified list of nodes
#
export SKIP_EQ_ESC=true
/usr/es/sbin/cluster/sbin/cl_on_node -cspoc "-f $DEBUG -n $_NODE_LIST" $flag $operand "$*"
return $?