0

I amrunning below script in KSH shell. I want to run the loop for 6 times to call Java program and in betwen if there is no exception found , then it should return =0. if in all the 6 iteration, we found any exception then it should return 3.

integer max=7;i=1

while [[ $i -lt $max ]]
do
    Java call statement;
    error_cnt=`$processing_file | grep -i excption | wc -l `
    if (( $error_cnt == 0 ))
    then
        return_code=0;
        break
    else
       Continue with java call 
    fi 
    (( i = i + 1 ))
done

If in all the 6 iterations still we finds exceptions then it should return 3.

1 Answer 1

0

Don't forget to define $processing_file. Also, you can just grep that file directly

Then, you're breaking out of your loop if there a no errors, when you want to break out if there are errors. Then, after your loop breaks or finishes, you want to actually return with the $return_code.

integer max=7;i=1
integer return_code=0

while [[ $i -lt $max ]]
do
    Java call statement;
    error_cnt=`grep -i exception $processing_file | wc -l`
    if (( $error_cnt != 0 ))
    then
        return_code=3;
        break
    # you don't need an else here, since continuing is the default
    fi
    (( i = i + 1 ))
done
# return with the code you specify
return $return_code
2
  • Thanks Tim. But how the loop will return code 0 in case there is no exception in the processing file.
    – John
    Commented Nov 17, 2020 at 4:09
  • @John - we're defining the 0 up at the top, in integer return_code=0. If no errors change that, then that 0 will fall all the way to the bottom of the script and be returned. Commented Nov 17, 2020 at 19:28

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .