If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Unix Shell Scripts > unix loop syntax getting infinite loop ...

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 11-15-09, 08:05
MIKELALA MIKELALA is offline
Registered User
 
Join Date: Nov 2009
Posts: 45
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 08:15.
Reply With Quote
  #2 (permalink)  
Old 11-15-09, 11:53
mike_bike_kite mike_bike_kite is offline
vaguely human
 
Join Date: Jun 2007
Location: London
Posts: 2,519
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?
Reply With Quote
  #3 (permalink)  
Old 11-29-09, 00:18
sco08y sco08y is offline
Registered User
 
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))
Reply With Quote
  #4 (permalink)  
Old 11-29-09, 00:31
sco08y sco08y is offline
Registered User
 
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.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On