#!/bin/ksh93
#  ALTRAN_PROLOG_BEGIN_TAG
#  This is an automatically generated prolog.
#
#  Copyright (C) Altran ACT S.A.S. 2017,2018,2019,2021.  All rights reserved.
#
#  ALTRAN_PROLOG_END_TAG
#
# IBM_PROLOG_BEGIN_TAG 
# This is an automatically generated prolog. 
#  
# 61haes_r721 src/43haes/usr/sbin/cluster/events/utils/cl_echo.sh 1.17.1.1 
#  
# Licensed Materials - Property of IBM 
#  
# COPYRIGHT International Business Machines Corp. 1990,2016 
# 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
# @(#)  7d4c34b 43haes/usr/sbin/cluster/events/utils/cl_echo.sh, 726, 2147A_aha726, Feb 05 2021 09:50 PM


###############################################################################
#
#  Name:  cl_echo
#
#  This routine logs messages to standard error
#
#  Arguments:    message text to be logged
#  Usage:        cl_echo message_id, arguments, variables
#  Returns:      0 - success
#                2 - bad number (0) of arguments
#  Environment:  VERBOSE_LOGGING,PATH,NLSPATH
#
###############################################################################

PROGNAME=${0##*/}
export PATH="$(/usr/es/sbin/cluster/utilities/cl_get_path all)"

# always print a timestamp with the message
print -n -u2 "$(date +"%h %e %Y %H:%M:%S")"
MSG_ID=$1
shift


# check for possible bad invocation
if (( $# < 1 ))
then
   dspmsg scripts.cat 1 "usage: $PROGNAME messageid (default) message" $PROGNAME >&2
   exit 2
else

   dspmsg scripts.cat $MSG_ID "$@" >&2

   ####################################################################
   # check if this is a client or server environment
   ####################################################################
   if [[ ! -f "/usr/es/sbin/cluster/clstrmgr" ]]
   then
      # This is a client environment, simply run dspmsg and exit
      exit 0
   fi
   # Read the HACMPlogs ODM for the pathname of the hacmp.out log file
   # If the ODM is empty or corrupted, use /var/hacmp/log/hacmp.out

   DESTDIR=$(clodmget -q "name = hacmp.out" -f value -n HACMPlogs)
   if [[ -z $DESTDIR ]] ; then
	   DESTDIR="/var/hacmp/log"
   fi

   HACMP_OUT_FILE="${DESTDIR}/hacmp.out"
   : $PROGNAME: using $HACMP_OUT_FILE for clsynclog

   #	Now, sync the log file to disk
   clsynclog $HACMP_OUT_FILE >/dev/null 2>&1

fi

return 0
