The loop that dosent work

I have a serious problem and Im sure im just doing something stupid

######Start Load 
while [ `< /export/home/mldwh/rkem_refresh/int_load/logs/iteration.log` -lt 15 ]
do
         /export/home/mldwh/rkem_refresh/int_load/scripts/rkem_refresh.sh
         sleep 10
         while [ -a /export/home/mldwh/rkem_refresh/int_load/logs/int_rkem_move_running.txt ]
         do 
   					sleep 5 
				done
done


######Log and Runstats 
sleep 10
echo "2nd 15 iterations finished" >> /export/home/mldwh/rkem_refresh/int_load/logs/Int_master.log
echo 0 > /export/home/mldwh/rkem_refresh/int_load/logs/iteration.log
db2 "CALL SYSPROC.ADMIN_CMD('runstats on table CENDW.DW_RKEM_MOVE_TBL with distribution and detailed indexes all shrlevel change')" >> /export/home/mldwh/rkem_refresh/int_load/logs/Int_master.log
db2 "CALL SYSPROC.ADMIN_CMD('runstats on table CENDW.DW_RKEM_MOVE_UPDATE_TBL with distribution and detailed indexes all shrlevel change')" >> /export/home/mldwh/rkem_refresh/int_load/logs/Int_master.log
sleep 10


######Start Load 
while [ `< /export/home/mldwh/rkem_refresh/int_load/logs/iteration.log` -lt 15 ]
do
         /export/home/mldwh/rkem_refresh/int_load/scripts/rkem_refresh.sh
         sleep 10
         while [ -a /export/home/mldwh/rkem_refresh/int_load/logs/int_rkem_move_running.txt ]
         do 
   					sleep 5 
				done
done

What I want to do is run the .sh file 15 times and then do some stuff and then run the .sh file 15 times again. I put the loop inside the loop (where i think my problem is) to make sure that the outer loop waited untill the .sh file was done before calling it again.

But what I am getting......ohh man this thing is spawning so many instances of the code that I have to chmod -x just to stop it.

So where am i going wrong?

What shell are you running that in? - it's not valid bourne at any rate...

you specified a while loop that do repetition if some counter is less than 15. Where is the counter? I presume its the value in the iteration.log file and int_rkem_move_running.txt files? if it is, then you have to update them to reflect a new counter everytime.

Im in ksh...

Im lost regarding your post. are both of these supposed to be imbeded in each other?....how do i use this info?

The counter is in the iteration.log file and it is incrmented durring the last step of the .sh file

the int_rkem_move_running.txt is a "seed" file that is created at the begining of the .sh script and deleted at the end of the .sh script.

The iteration seems to work I see it loop, but for some reason it seems to call the .sh file many times before it finishes. I.E. the loop isnt waiting for the .sh to finish before it calls another one.

I dont get it....

I'm just noting that those two lines I quoted are not valid in bourne - thus prompting the question of which shell.

The `< file` thing is unique to ksh as far as I can tell and is an aliase for wc
The -a makes no sense to me at all - I'm used to it being a logical and between two expressions.

the -a means while exhists. i only work in ksh right now...

any idea about the loop? im realy stuck here

This is valid ksh syntax....

$ cat num
10
$ echo $(< num)
10
$ echo `< num`
10
$ [ -a num ] && echo ok
ok
$

$(< num) is the contents of the file called num. I have seen this often. I have never seen `< num` before and it is not documented, but it seems to work. Many versions of ksh allow -a or -e to test if an item is a file sysetm object of any kind (not just a file, not just a directory, not just a symlink, etc). But -e and -a are not super standard even among versions of ksh.

i think its also benefiical if you show your other .sh scripts as well.

I agree about needing more info. A loop must initialize a loop counter, increment it, and test it. I see one script that sets /export/home/mldwh/rkem_refresh/int_load/logs/iteration.log to zero. And another that tests it. No increment though. And I do not see how these script fragments inter-relate. :confused:

also, using kill -15 is a better way to stop a runaway program than to do a chmod -x on something.

I was hopeing not to burden you with all the ugly details of the other .sh but you asked for it :slight_smile:

#!/bin/bash -x
. /export/home/mldwh/rkem_refresh/int_load/scripts/rkem_functions.sh

######Set Path Variables
Path_Variables /export/home/mldwh/rkem_refresh/logs/ rkem_master.log


######Set Username and Password Variables
Username_Variables $RKEM_LOG rkem_master.log


######Capture MainFrame Time
RKEM_Mainframe_time $RKEM_LOG rkem_master.log $IDB1USER $IDB1PWD


######Set Master Date Variable
Master_date $RKEM_LOG rkem_master.log


######Audit Process Start
Process_Audit_Start $RKEM_LOG rkem_master.log $TPCUSER $TPCPWD $MASTERDATE "'RKEM REFRESH'" 'Start RKEM Delta Load'


######Start Full Process File
echo -==Create Start and Stop files==- >> $RKEM_LOG"rkem_master.log"
db2 -x "select rtrim(char(year(max(CHDATETIME)))) || '-' || substr( digits (month(max(CHDATETIME))),9) || '-' || substr( digits (day(max(CHDATETIME))),9) From CENDW.DW_RKEM_MOVE_TBL" > $RKEM_LOG"rkem_start_date.txt"
db2 -x "select substr( digits (hour(max(CHDATETIME))),9) || '.' || substr( digits (minute(max(CHDATETIME))),9) || '.' || substr( digits (second(max(CHDATETIME))),9) From CENDW.DW_RKEM_MOVE_TBL" > $RKEM_LOG"rkem_start_time.txt"
echo -== Start Date `cat $RKEM_LOG"rkem_start_date.txt"`==- >> $RKEM_LOG"rkem_master.log"
echo --==Start time `cat $RKEM_LOG"rkem_start_time.txt"`==- >> $RKEM_LOG"rkem_master.log"


######Create Hold File for RKEM Load Process
Hold_File $RKEM_LOG rkem_master.log 'RKEM MOVE DELTA REFRESH RUNNING' int_rkem_move_running.txt


######Call RKEM MOVE Extract PROCESS
RKEM_Call_Process $RKEM_LOG rkem_master.log $RKEM_SCRIPT extract_rkem_move.sh 'Start RKEM Process'


sleep 15


######Call RKEM MOVE Load PROCESS
RKEM_Call_Process $RKEM_LOG rkem_master.log $RKEM_SCRIPT load_rkem_move.sh 'Call $RKEM_SCRIPT"load_rkem_move.sh"'


######Wait for RKEM MOVE PROCESS to Complete
File_Wait $RKEM_LOG rkem_master.log rkem_move_delta_running.txt 'Start time waiting for STG RKEM to load' 'Finish time waiting for STG RKEM to load'


######Test that Load completed
Process_Test $RKEM_LOG rkem_master.log "'RKEM REFRESH'" "'RKEM REFRESH - RKEM MOVE'" $MASTERDATE $RKEM_SCRIPT merge_rkem_move.sh 'RKEM STG LOAD INCOMPLETE' INCOMPLETE_RKEM_STG_LOAD.TXT


sleep 15


######Wait for RKEM MOVE MERGE PROCESS to Complete
File_Wait $RKEM_LOG rkem_master.log rkem_move_merge_running.txt 'Start time waiting for STG RKEM MERGE ' 'Finish time waiting for STG RKEM MERGE'


######Test that Merge completed
Process_Test $RKEM_LOG rkem_master.log "'RKEM REFRESH'" "'RKEM REFRESH - MERGE RKEM MOVE'" $MASTERDATE $RKEM_SCRIPT merge_rkem_move_update.sh 'RKEM MOVE MERGE INCOMPLETE' INCOMPLETE_RKEM_MOVE_MERGE.TXT


sleep 15


######Wait for RKEM MOVE MERGE UPDATE PROCESS to Complete
File_Wait $RKEM_LOG rkem_master.log rkem_move_update_merge_running.txt 'Start time waiting for RKEM UPDATE MERGE' 'Finish time waiting for RKEM UPDATE MERGE'


######Test that Update Merge completed
Process_Test $RKEM_LOG rkem_master.log "'RKEM REFRESH'" "'RKEM REFRESH - MERGE RKEM MOVE UPDATE'" $MASTERDATE $RKEM_SCRIPT update_rkem_move.sh 'RKEM MOVE UPDATE MERGE INCOMPLETE' INCOMPLETE_RKEM_MOVE_UPDATE_MERGE.TXT


sleep 15


######Wait for RKEM MOVE UPDATE PROCESS to Complete
File_Wait $RKEM_LOG rkem_master.log rkem_move_update_running.txt 'Start time waiting for RKEM MOVE UPDATE ' 'Finish time waiting for RKEM MOVE UPDATE'


######Test that Update completed
Last_Process_Test $RKEM_LOG rkem_master.log "'RKEM REFRESH'" "'RKEM REFRESH - UPDATE'" $MASTERDATE 'RKEM MOVE UPDATE INCOMPLETE' INCOMPLETE_RKEM_MOVE_UPDATE.TXT


######Audit FULL PROCESS
Process_Audit_Stop $RKEM_LOG rkem_master.log $TPCUSER $TPCPWD "'RKEM REFRESH'" 'Finish RKEM Delta Load'


######Set Iteration Log
value=`< /export/home/mldwh/rkem_refresh/int_load/logs/iteration.log`
final=`expr $value + 1`
echo $final > /export/home/mldwh/rkem_refresh/int_load/logs/iteration.log


######Remove Hold File for RKEM Load
Remove_Hold_file $RKEM_LOG rkem_master.log int_rkem_move_running.txt

Notice near the bottom where I set the iteration log

######Set Iteration Log
value=`< /export/home/mldwh/rkem_refresh/int_load/logs/iteration.log`
final=`expr $value + 1`
echo $final > /export/home/mldwh/rkem_refresh/int_load/logs/iteration.log

Does this shed more light onto the problem? Im realy behind on a deadline and I need this loop to work so that I can enjoy the vacation that I am on. Any info would be great

and now a bigger problem

kill -15 isnt killing the pids....