#!/bin/sh
##################################################################
# Name: /IBM/bin/lcmaStart
# Purpose: Starts one lcma session and logs lcma cout's to
#           /tmp/lcma/lcma.log
#          Then sends success or error trap to server with task oid
#          TCM gets log as needed using backup task
##################################################################

# run lcma and log output, overwriting old log
/IBM/bin/lcma $@ > /tmp/lcma/lcma.log 2>&1

# get the lcma return value, for success or error trap
VAL=$?
if [ $VAL -eq 0 ]
then
	ENTERPRISE=3
else
	ENTERPRISE=4
fi

# get task id from -t parameter, if no t param then TASK_ID is empty
TASK_ID=`echo $@ | sed -n "s/.* -t \([^ ]*\).*$/\1/p"`

# send lcma completion success or error trap with task oid
/IBM/bin/gentrap 6 $ENTERPRISE /IBM/bin/lcmaStart $TASK_ID >> /tmp/lcma/lcma.log 2>&1

# cp lcma.log to client_task.log so we can use lcma to get it
cp /tmp/lcma/lcma.log /var/log/lcma/client_task.log
