Run the for loop in parallel

I have the below code which runs on multiple databases , but this runs one-after-one. I will need this to run in parallel so that i could save a lot of time. Please help!!! Thanks in advance

for Db in `cat /var/opt/oracle/oratab |egrep -v "ASM" |grep -v \# |cut -d\: -f1`
do
{
export ORACLE_SID=$Db
$ORACLE_HOME/bin/sqlplus -s /nolog <<EOF
connect / as sysdba
....
....
exit
EOF
}
done

This is some ugly
for Db in `cat /var/opt/oracle/oratab |egrep -v "ASM" |grep -v \# |cut -d\: -f1`

Replace `` with parentheses $()
Do not cat data to commands, when they can read it them self. cat file | grep test , use grep test file
Why using bot egrep and grep ?
If I am correct, you like first field of line that does not contain for ASM nor #
Many commands, that can be down with one command.

for Db in $(awk -F: '!/ASM|#/ {print $1}' /var/opt/oracle/oratab)

I can not help with the running it multiple.

thanks for the reply.However I am looking for parallel option here in priority

for Db in `cat /var/opt/oracle/oratab|cut -d\: -f1`do{export ORACLE_SID=$Db$ORACLE_HOME/bin/sqlplus -s /nolog <<EOFconnect / as sysdba........exitEOF}done
 

You can try something like this using xargs.

awk -F: '!/ASM|#/{print $1}' /var/opt/oracle/oratab | xargs -I% -P5 bash -c './sql_script %'

sql_script

#!/bin/bash
export ORACLE_SID=$*
$ORACLE_HOME/bin/sqlplus -s /nolog <<EOF
connect / as sysdba
....
....
exit
EOF

man xargs

       -P max-procs
              Run up to max-procs processes at a time; the default is 1.  If max-procs is 0, xargs will  run
              as  many  processes  as  possible at a time.  Use the -n option with -P; otherwise chances are
              that only one exec will be done.

Not tested, only suggestion.

--ahamed

Thanks Ahamad,
But this does not seem to be working for me. Please provide alternatives.
Looking to run the below in parallel on all databases, rather then one after one

for Db in `grep -v \# /etc/oratab|cut -d\: -f1|egrep -v "+ASM"`
do
export ORACLE_SID=$Db
sqlplus -s /nolog <<EOF
connect / as sysdba
startup
exit
EOF
done

Try just placing an & char after the closing } to execute in background. I'm not sure this will save much time, as side effects may eat up your parallel processing advantages.