Complex loop...

Hi,

I did a lot of search for this but I could not find it, so I am posting it here....Please help.

I have a situation where I need to do polling or sleep for a while...here is what I have..

#! /usr/bin/sh
job1 runs > result1.txt
RESULT1_CNT=`wc -l result1.txt | awk '{ print $1 }'`
if[ RESULT1_CNT -gt 0 ]
then
while [ RESULT1_CNT -gt 0 ]
do
JOb2 runs
RESULT1_CNT=RESULT1_CNT-1
done
else
#This is the part I am struggling for....
#here it should sleep for specified time and run job1 again...
#if the RESULT1_CNT is not greater than 0 three consecutive times
#then it should exit

any help is appreciated...

Thanks,

Girinath.

This is a start:

#! /usr/bin/ksh

let consecutive=-1
while true
do
    job1 runs > result1.txt
    RESULT1_CNT=`wc -l result1.txt | awk '{ print $1 }'`
    if [ $RESULT1_CNT -lt 1 ]; then
        let consecutive=$consecutive+1
        if [ $consecutive -eq 2]; then  # note: -1 + 3 = 2
             exit 1                  
        fi 
    else
        let consecutive=-1
    fi
    if[ $RESULT1_CNT -gt 0 ]; then
        while [ RESULT1_CNT -gt 0 ]
        do
           JOB2 runs
           RESULT1_CNT=RESULT1_CNT-1
        done
    fi
    sleep 60
done

Note that I used ksh...