#!/bin/ksh
# IBM_PROLOG_BEGIN_TAG 
# This is an automatically generated prolog. 
#  
# 61haes_r714 src/43haes/usr/sbin/cluster/cspoc/utilities/clgetcmdoutput.sh 1.1 
#  
# Licensed Materials - Property of IBM 
#  
# COPYRIGHT International Business Machines Corp. 1996 
# 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 
#
# @(#)55	1.1 src/43haes/usr/sbin/cluster/cspoc/utilities/clgetcmdoutput.sh, hacmp.cspoc, 61haes_r714 6/28/96 15:57:48
# $Id: clgetcmdoutput.sh,v 1.2 1996/06/11 11:18:16 nerd Exp $

USAGE="usage: $0 <nodename> <command> <file>"
TMPFILE="/tmp/clgetcmdoutput.$$"
RC=0

function cleanup
{
    [[ $_DEBUG -lt 4 ]] && rm -f $TMPFILE
    exit
}

trap cleanup EXIT

[[ -z "$DEBUG" ]] || set -x

[[ $# -ne 3 ]] && {
    print $USAGE
    exit 2
}

node=$1
cmd=$(print $2 | tr ":" " ")
file=$3
CMD_FOUND="FALSE"

[[ -f "$file" ]] || {
    print "$0: file \"$file\" not found"
    exit 1
}    

sed -e "/${node}:[ ]*/ !D
	s///" < $file > $TMPFILE

(while read LINE ; do
    [[ "$LINE" = "__CSPOC_NODE_CMD__${cmd}" ]] && {
	CMD_FOUND="TRUE"
	break
    }
done
while read LINE ; do
    if [ "${LINE%%[0-9]*}" = "__CSPOC_RETCODE__" ] ; then
	RC=${LINE#__CSPOC_RETCODE__}
	break
    else
	print "$LINE"
    fi
done) < $TMPFILE

# if nothing found return a 1
[[ "$CMD_FOUND" = "FALSE" ]] && exit 1

exit RC
