1

Is there a way send multiple sqlplus commands within a loop but waiting for one to run with success in order for the next one to start ? Here is a sample of my code. I have tried to add that sleep 15 because the functions that I'm going to execute are taking like 10-20s to run. I want to get rid of that 15s constant and make them run one after the other.

if [ "$#" -eq 1 ]; then
   checkUser "$1"
   while read line; do
     sqlplus $user/$pass@$server $line
     sleep 15
   done < "$wrapperList"
fi
1
  • Oh, I thought that it was going to send sqlplus commands in parallel. It's just a list of .sql files that will be used in the sqlplus command. Did not tried, that was my first assumption. I'll try and I'll come back with an answer. Thanks Commented Dec 20, 2017 at 8:25

1 Answer 1

1

The instruction in a while loop are done in sequence. It would be equivalent to do like that, using ; to chain instructions:

sqlplus $user/$pass@$server $line1 
sqlplus $user/$pass@$server $line2

So you don't need the sleep 15 here, since the sqlplus commands will not be called in parallel. The way you did it already is calling them one after the other.

Nota: It is even better to stop running if first line did not return correctly, using && to say: run only if previous return code is 0

sqlplus $user/$pass@$server $line1 &&\ 
sqlplus $user/$pass@$server $line2

To have this in the while loop:

   checkUser "$1"
   while read line; do
     sqlplus $user/$pass@$server $line
     RET_CODE=$? # check return code, and break if not ok.
     if [ ${RET_CODE} != 0 ]; then
       echo "aborted." ; break
     fi
   done < "$wrapperList"

On the other hand, When you want to run in parallel, syntax is different, like here: Unix shell script run SQL scripts in parallel

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.