Cant debug shell script

Hi I am relatively new in shell scripting Below is the code which i developed but for some reason, it keeps giving me error:
/apps/bss/BatchProg/at1/batch/scripts/ksh/TBATLC02.ksh[30]: syntax error at line 41 : `then' unmatched

#!/usr/bin/ksh
#####################################################################
#    
#    DESCRIPTION: This jobs checks for following condition -
#    if(8 am)
#        post "EndOfDay.log" file in the output directory of the 
#        job
#    else if(wave file found)
#        post "ExecuteWave.log" file in the output directory of    #        the job
#    else if(camapign contacts file found)
#        post "ExecuteCampaignCOntacts.log" file in the output    #           directory of the job
#    else
#        keep looping till its 8 am.
#
#####################################################################

SRC_DIR=$1  
DEST_DIR=$2
RUN_CHECK=1

#remove any log file from th eoutput directory of the job
rm $DEST_DIR/*

#remove all ctl and eot files
rm $SRC_DIR/*.ctl
rm $SRC_DIR/*.eot

#Keep checking for a file till a wave/ campaign contact file is found #till it is 8 am 
while [ $RUN_CHECK -gt 0 ]
do
    #check for current time
    TIME=`date "+%H%M"`
    echo "Time is :"$TIME   # For testing
    if [ $TIME -gt 0800 ] ; then
        echo ''>$DEST_DIR/EndOfDay.log
        RUN_CHECK=0
        
    else
        #check for wave file
        WAVE_FILE=`ls $SRC_DIR/ATHENIAN_IF927_LoadCampaignWave_*.dat`
        WAVE_COUNT=${#WAVE_FILE}

        

        if [ WAVE_COUNT -gt 10 ] ; then
            echo ''>$DEST_DIR/ExecuteWave.log
            RUN_CHECK=0
        
        else
            #check for Campaign Contact file
            CAMPAIGN_CONTACTS_FILE=`ls $SRC_DIR/ATHENIAN_IF927_LoadCampaignContact_*.dat`
            CAMPAIGN_CONTACTS_COUNT=${#CAMPAIGN_CONTACTS_FILE}

            if [ CAMPAIGN_CONTACT_COUNT -gt 10 ]; then
                echo ''>$DEST_DIR/ExecuteCampaignContacts.log            
                RUN_CHECK=0
        
            fi
        

        fi
        

    fi

done

Any help would be highly appreciated

Hi,

Try if condition as below

if [[ $TIME -gt 0800 ]]
then


fi
1 Like

Your problems are at lines 45 and 54, you're missing the '$' sigil for the variables:

if [ $WAVE_COUNT -gt 10 ] ; then
            echo ''>$DEST_DIR/ExecuteWave.log
            RUN_CHECK=0
        
        else
            #check for Campaign Contact file
            CAMPAIGN_CONTACTS_FILE=`ls $SRC_DIR/ATHENIAN_IF927_LoadCampaignContact_*.dat`
            CAMPAIGN_CONTACTS_COUNT=${#CAMPAIGN_CONTACTS_FILE}

            if [ $CAMPAIGN_CONTACT_COUNT -gt 10 ]; then

BTW, you can use

: > file

to truncate/create a file, instead of using echo.

1 Like

Run the script in debug mode, add this line below the the line #!/bin/ksh:

set -x
1 Like

Thank you all guys... the set - x was especially helpful!
cheers