Command line not getting assigned in script.

I am running the following script and passing the following command line arguments :

DBCheckSum_control CA_SITE CA_SITE

Can someone please tell me, why my command line args are not being accepted and assigned to variable "TABLE_NAME'' and "ACTION_TYPE"??


usage()
{
print "Usage: ${0} { inc_non_primary }"
print "Usage: ${table_name} ${ c}"
}

option_count=${#}

. /opt/projects/gsd/scripts/functions gsd > /dev/null 2>&1



 
 if [ "${option_count}" -eq 1 ]
 then
 	ACTION_TYPE="${1}"
 fi	 
 
 if [ "${option_count}" -eq 2 ]
 then
 	TABLE_NAME=${1}
 	ACTION_TYPE=${2}  			  
 	
 	echo "${ACTION_TYPE}" 
	echo "${TABLE_NAME}"
 fi	
 
 if [ "${option_count}" -gt 2 ]
 then
      usage
      exit 1
   fi

APPLNAME="DBCheckSum"
LOGFILE="${NIGHTLY_LOG_DIR}/${APPLNAME}.${DATETIME_STAMP}.log"
ERROR_LOGFILE="${NIGHTLY_LOG_DIR}/${APPLNAME}.${DATETIME_STAMP}.err"

if [ "${CURR_USER}" != "srvcdesk" ]; then
        log_msg "You must be srvcdesk to execute this script, ABORTING!"
        exit 5
fi


case "${option_count}" in
  1)	java -Xms256m -Xmx1536m "${APPLNAME}" "${ACTION_TYPE}" > "${LOGFILE}" 2> "${ERROR_LOGFILE}"
  	;;
  2)    java -Xms256m -Xmx1536m "${APPLNAME}" "${TABLE_NAME}" "${ACTION_TYPE}" > "${LOGFILE}" 2> "${ERROR_LOGFILE}"
  	;;
  *)	usage;
	exit 1;;
esac




---------- Post updated at 01:22 PM ---------- Previous update was at 01:21 PM ----------

Sorry passing Command line args as :

DBCheckSum_control CA_SITE inc_non_primary

are you running

your_script_name.sh arg1 arg2

or

your_script_name arg1 arg2

?

Just to write something cleaner, you could do something like:

if [ "${option_count}" -eq 1 ] ;then
  ACTIOn_TYPE=$1

elif ["${option_count}" -eq 2 ];then
    ACTION_TYPE=$2
    TABLE_NAME=$1
else
     usage
     exit 1;
fi

By the way, your problem may come from the fact that you forget the ";then" statement after the if condition.

Hope it'll help..
Regards

#!/bin/ksh

usage()
{
    # print error to the stderr
    print "Usage: ${0} { inc_non_primary }"  >&2
    print "Usage: ${table_name} ${ c}"        >&2
}

####
# maybe your functions include also options_count handling ? - change order
# or next line include error => script will exit, usually never set output redirect when use 
# . 
#. /opt/projects/gsd/scripts/functions gsd > /dev/null 2>&1
# maybe you try to load file gsd ?
# better method to load something to this process 
f=/opt/projects/gsd/scripts/functions/gsd
[ -f "$f" ] && . $f  || print "no $f" >&2

option_count=$#

[ "$option_count" -gt 2 ] && usage && exit 1
[ "$option_count" -lt 1 ] && usage && exit 1

#CURR_USER: where set ? Usually LOGNAME
if [ "$CURR_USER" != "srvcdesk" ]; then
        log_msg "You must be srvcdesk to execute this script, ABORTING!"
        exit 5
fi

# make default, you can use { }, but not needed in your cases
ACTION_TYPE="$1"

if [ "$option_count" = 2 ]  # both are possible: string = and numeric -eq, 
then
 	TABLE_NAME="$1"
 	ACTION_TYPE="$2"			  
 	print "$ACTION_TYPE" 
	print "$TABLE_NAME"
fi	

APPLNAME="DBCheckSum"
LOGFILE="$NIGHTLY_LOG_DIR/$APPLNAME.$DATETIME_STAMP.log"
ERROR_LOGFILE="$NIGHTLY_LOG_DIR/$APPLNAME.$DATETIME_STAMP.err"

case "$option_count" in
  1)	java -Xms256m -Xmx1536m "$APPLNAME" "$ACTION_TYPE" > "$LOGFILE" 2> "$ERROR_LOGFILE"
  	;;
  2)    java -Xms256m -Xmx1536m "$APPLNAME" "$TABLE_NAME" "$ACTION_TYPE" > "$LOGFILE" 2> "$ERROR_LOGFILE"
  	;;
esac

Thanks to Moumou & kshji !! the script worked both the ways. the problem was with the include functions file. I changed the order of it and got it a little lower just above

APPLNAME="DBCheckSum"
LOGFILE="$NIGHTLY_LOG_DIR/$APPLNAME.$DATETIME_STAMP.log"
ERROR_LOGFILE="$NIGHTLY_LOG_DIR/$APPLNAME.$DATETIME_STAMP.err"

that made it work :slight_smile: