#!/bin/ksh
#  ALTRAN_PROLOG_BEGIN_TAG                                                    
#  This is an automatically generated prolog.                                  
#                                                                              
#  Copyright (C) Altran ACT S.A.S. 2017,2021.  All rights reserved.  
#                                                                              
#  ALTRAN_PROLOG_END_TAG                                                      
#                                                                              
# IBM_PROLOG_BEGIN_TAG 
# This is an automatically generated prolog. 
#  
# 61haes_r721 src/43haes/lib/libcspoc/log_cmd.sh 1.1.1.2 
#  
# Licensed Materials - Property of IBM 
#  
# COPYRIGHT International Business Machines Corp. 1996,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/lib/libcspoc/log_cmd.sh, 726, 2147A_aha726, Feb 05 2021 09:50 PM
#
#   COMPONENT_NAME: CSPOC
#
#   FUNCTIONS:
#
#   ORIGINS:
#
#
#   (C) 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.
#
################################################################################
#
# Name:
#       log_cmd
#
# Description:
#       Creates a C-SPOC log file entry that consists of a date/time stamp
#       followed by all arguments except the first.  The first argument is
#       the name of the log file in which to pplace the entry.
#
# Arguments:
#       $1 - Full path of logfile 
#       $2 - AIX Command name
#	Remaining arguments are arguments of the AIX command
#
# Return Values:
#       0 - success
#       1 - failure
#
################################################################################
USAGE="USAGE: log_cmd <logfile> <command> [args]"

function log_cmd
{
    [[ -n $_NO_LOG_CMD ]] && return 0

    typeset LOGFILE
    LOGFILE=$1
    shift 1

    # Create the log file entry
    (
      print "$(LC_ALL=C /usr/bin/date '+%Y-%m-%dT%H:%M:%S')|$*"
    ) >> ${LOGFILE}
}

if [[ -n $@ && $@ == /* ]]	    # hack around ksh bug - make sure we got a path name
then
   bname=${0##*/}

   if [[ $bname == "log_cmd" ]]
   then
      log_cmd "$@"
   else
      # if cspoc path is not in PATH,
      # the basename comes calling file   

      tmp_log=/var/hacmp/log/cel$$_tmplog
      log_cmd "$tmp_log"
   fi
fi
