Cant debug shell script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Cant debug shell script
# 1  
Old 08-04-2010
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

Code:
#!/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
# 2  
Old 08-04-2010
Hi,

Try if condition as below

Code:
if [[ $TIME -gt 0800 ]]
then


fi

This User Gave Thanks to pravin27 For This Post:
# 3  
Old 08-04-2010
Your problems are at lines 45 and 54, you're missing the '$' sigil for the variables:
Code:
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
Code:
: > file

to truncate/create a file, instead of using echo.
This User Gave Thanks to pludi For This Post:
# 4  
Old 08-04-2010
Run the script in debug mode, add this line below the the line #!/bin/ksh:
Code:
set -x

This User Gave Thanks to Franklin52 For This Post:
# 5  
Old 08-05-2010
Thank you all guys... the set - x was especially helpful!
cheers
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

"Help debug the shell script"

Hello All, I have got a section of shell script which was working earlier but now it is giving some different results: MSG= while true do themenu getchar = case $answer in 1) export_Config_tables;; 2) export_config_tables_file;; 3)... (1 Reply)
Discussion started by: bghosh
1 Replies

2. Ubuntu

Debug script

How can I debug this script? I want to know what it is doing or not doing? #!/bin/bash # # if ; then # Do the thing you want before suspend here echo "we are suspending." > /tmp/systemd_suspend_test.txt elif ; then # Do the thing you want after resume here echo "and we are... (21 Replies)
Discussion started by: drew77
21 Replies

3. Shell Programming and Scripting

Logging perl and shell debug mode.

I have a shell program which calls a perl program. I am running the shell program with command; $ ksh -x <prog_name> Inside the shell program, I am calling perl with warnings. I want to capture the entire output as it comes on screen. The command I tried is: $ ksh -x... (1 Reply)
Discussion started by: som.nitk
1 Replies

4. Shell Programming and Scripting

How to compile or debug line by line in shell script?

I know about bash -x, set -x and -v but disappears from Command Line Interface in fraction of second ...... I am looking for a command or script ..complies each line and shows the output after executing each line ....( similar what we have in C ) Thanks in Advance (2 Replies)
Discussion started by: frintocf
2 Replies

5. Shell Programming and Scripting

Help with debug the script

Hi, I have this script, searches and sets variables, then searches and sets more variables from multiple files. I'd need to debug it a bit. #!/bin/bash egrep $1 `find | grep MAGT` >/tmp/resRA-$$ thread=`sed -n '/{0x/ {s/^.*{0x\(*\).*/\1/p;q}' /tmp/resRA-$$` tag=`sed -n '/Tag=/... (5 Replies)
Discussion started by: Vitoriung
5 Replies

6. Shell Programming and Scripting

Problem with the script, help me debug

Hi, When i run the script ./script.sh sun, this give me no output, it should give me the list of file. If i run the script without the argument it should send me echo inside usage(). What is the problem? please help -Adsi #!/bin/sh ROOT_PATH=/net/icebox/vol/local_images/spins... (2 Replies)
Discussion started by: asirohi
2 Replies

7. Shell Programming and Scripting

Please help to debug a small shell script (maybe AWK problem)?

Hi Buddies, The following is shell scripts which was borrowed from linux box for load average check. it runs good. (this structure is simple, when load average is too high, it will send alert to user) #!/usr/bin/ksh # Set threshold for 1, 5 and 15 minture load avarage # configured for... (4 Replies)
Discussion started by: GreatJerry
4 Replies

8. UNIX for Advanced & Expert Users

How can debug our UNIX shell script?

Hi all, i have two simple questions here... 1. i want to know that how to debug the UNIX shell script? 2. is there any way to handling the exception in UNIX shell script like oracle exception handling? Please provide me those details it would be great help/ Thanks and Regards, MPS... (3 Replies)
Discussion started by: psiva_arul
3 Replies

9. Shell Programming and Scripting

debug this script

echo "input time in hhmmss" read $st h=`echo $st | cut -c1-2` min=`echo $st | cut -c3-4` s=`echo $st | cut -c5-6` echo "input time in hhmmss" read $end h1=`echo $end | cut -c1-2` min1=`echo $end | cut -c3-4` s1=`echo $end | cut -c5-6` x= `expr $h /* 60 + $min` y= `expr $h1 /* 60 +... (8 Replies)
Discussion started by: abhishek27
8 Replies
Login or Register to Ask a Question