Results 1 to 4 of 4
  1. #1
    Join Date
    Nov 2009
    Posts
    56

    Unanswered: unix loop syntax getting infinite loop ...

    Hello all,

    GOOD MORNING.

    When i run the code ( its .ksh script) i am getting infinite loop


    Appreciate your help in this regard ..


    =============================
    #!/bin/ksh
    ERROR_CDE=""
    MAX_LOOP_COUNT=3
    MIN_LOOP_COUNT=1
    TRAP_CODES="(ORA-04068|ORA-04061|ORA-06512)"
    echo "Start of Process:$STARTTIME" >$LOGFILE

    # Read the files from ccdbcen directory:
    cd $TPE_CCDB_IN_DIR
    for strFileName in `ls -trp CCDB* 2> /dev/null`
    do

    if [[ $SkipInd != "Y" ]]
    then
    echo "File Name: $strFileName<br>" >$LOGFILE.$strFileName
    echo "File Name: $strFileName"
    while [[ $MIN_LOOP_COUNT -le $MAX_LOOP_COUNT ]]
    do
    $ORACLE_HOME/bin/sqlplus -s >>$LOGFILE.$strFileName<< EOF
    $TPE_LOGIN_STRING
    set serveroutput on;
    whenever sqlerror exit 1;
    whenever oserror exit 1;
    begin
    -- Load the file into a work table and process
    PKG_TPE_FA_LOAD.LOAD_NEW_CASES('$TPE_STAGE_IN_DIR' ,'$strFileName','$FA_REJECT_LIST');
    end;
    /
    EOF
    ERROR_MSG=`cat $LOGFILE.$strFileName`
    ERROR_CDE=`egrep $TRAP_CODES $LOGFILE.$strFileName | sed 's/:.*//'`
    echo "\nTHE ERROR CODE IS $ERROR_CDE"
    if [[ $ERROR_CDE = "" ]]
    then
    break
    else
    continue
    fi
    ((MIN_LOOP_COUNT=MIN_LOOP_COUNT+1))
    done

    fi
    done
    ======================

    output..

    THE ERROR CODE IS ORA-06512
    ORA-06512
    ORA-06512
    ORA-06512
    ORA-06512
    ORA-06512
    ORA-06512
    .
    .
    .
    .
    .
    Last edited by MIKELALA; 11-15-09 at 09:15.

  2. #2
    Join Date
    Jun 2007
    Location
    London
    Posts
    2,527
    Quote Originally Posted by MIKELALA
    Appreciate your help in this regard ..
    • There is no indenting of your code so the program is extremely difficult to read.
    • The variable SkipInd is not set so I'm unsure why you don't get an error here.
    • There are no echo's within the loops so it's difficult to see where, why or if it's actually looping.
    • Shouldn't there be a delay between attempts at loading the data?
    • I looked up the error codes and they seem to indicate PLSQL errors - shouldn't these be fixed first? why are you expecting these errors to go after attempting to reload the data?
    • The variable ERROR_CDE contains all the occurrences of the trapped codes - if there were 1000's of errors thrown while loading the data then it will contain 1000's of ORA-xxxx values - are you sure these aren't what are being printed out?
    • Have you invested in that book on Unix shell programming yet?

  3. #3
    Join Date
    Oct 2002
    Location
    Baghdad, Iraq
    Posts
    697

    This problem brought to you by the lack of static code analysis of shell scripts!

    I'll second everything that Mike said, but I did catch a pretty likely culprit.

    The continue statement jumps back to the while condition, so the statement incrementing MIN_LOOP_COUNT is never executed.

    Code:
    if [[ $ERROR_CDE = "" ]] 
    then
       break 
    else
       continue
    fi
    ((MIN_LOOP_COUNT=MIN_LOOP_COUNT+1))
    According to man ksh:

    Code:
           - continue [ n ]
                  Resume the next iteration of the enclosing for, while, until, or
                  select loop.  If n is specified, then resume at the n-th enclos-
                  ing loop.
    The fix is to remove the else clause entirely:

    Code:
    if [[ $ERROR_CDE = "" ]] 
    then
        break 
    fi
    ((MIN_LOOP_COUNT=MIN_LOOP_COUNT+1))

  4. #4
    Join Date
    Oct 2002
    Location
    Baghdad, Iraq
    Posts
    697
    Quote Originally Posted by mike_bike_kite View Post

    • The variable SkipInd is not set so I'm unsure why you don't get an error here.
    Ah, I was wondering about this too. Quoth the man page (works for bash, too): "Field splitting and file
    name generation are not performed on the words between [[ and ]]." So with an unset variable:

    Code:
    $ [ "$NOTDEFINED" == "" ] && echo yes 
    yes
    $ [ $NOTDEFINED == "" ] && echo yes
    ksh: [: argument expected
    $ [[ $NOTDEFINED == "" ]] && echo yes
    yes
    $ [[ "$NOTDEFINED" == "" ]] && echo yes
    yes
    Too bad shooting yourself in the foot is still the default action.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •