I'll show how to deal with it easily with an example based on my own scripts.
In this script I define a simple function run_sql(DESCR, SCRIPT, DATABASES), where
- DESCR - short description
- SCRIPT - sqlplus run arguments, ie script name and its parameters
- DATABASES - list of dbname defined above on which you want to run it
Then we can easily use it like this:
run_sql "1st script" "@sql1.sql param1" db1 db2
run_sql "2nd script" "@sql2.sql param1 param2 param3" db1 db2 db3
Here we execute:
- "sql1.sql" with 1 argument on db1 and db2
- "sql2.sql" with 3 arguments on db1,db2 and db3
And we save all output into own log files.
Full example with test output: https://gist.github.com/xtender/465951befeed7f0ae1a3fe112dcd7fe4
Simple script test.sh:
#!/bin/bash
# Here you can define your db connection strings:
db1=xtender/pass@PDB19C_11
db2=xtender/pass@PDB19C_11
db3=xtender/pass@PDB19C_11
#####################################################################
# functions:
# Function syntax: run_sql(DESCR, SCRIPT, DATABASES)
# where
# DESCR - short description
# SCRIPT - sqlplus run arguments, ie script name and its parameters
# DATABASES - list of dbname defined above on which you want to run it
run_sql(){
local DESCR="$1"; shift
local SCRIPT="$1"; shift
local databases=("$@")
echo =================================================
echo = $DESCR
echo = Going to execute $SCRIPT...
read -a res -p "Enter 'skip' to skip this step or press Enter to execute: "
if [[ $res = "skip" ]]
then
echo Skipping $SCRIPT...
else
echo Executing $SCRIPT...
for db in "${databases[@]}"
do
local cur=${!db}
echo Executing $SCRIPT on $db - $cur...
sqlplus -L -S ${cur} $SCRIPT >>log-$db.log 2>&1
echo Done.
done
echo =================================================
fi
}
#####################################################################
# Here we execute a script "sql1.sql" with one argument "param1" on db1 and db2:
run_sql "1st script" "@sql1.sql param1" db1 db2
# Here we execute a script "sql2.sql" with 3 arguments on db1,db2 and db3:
run_sql "2nd script" "@sql2.sql param1 param2 param3" db1 db2 db3
echo ============================================
echo === Done
echo ============================================
Then we can create sql scripts, for example sql1.sql and sql2.sql: sql1.sql requires one argument and sql2.sql - 3 arguments:
sql1.sql:
select '&1' as output from dual;
exit;
sql2.sql:
select
'&1' out1,
'&2' out2,
'&3' out3
from dual;
exit;
$nbris used nowhere ...commitbeing passed, so is that coming from whateverrunsqlis - either another script or a function in this script? Or on the command line when you call your shell script? The output is (partly - where is the prompt coming from?) what you see withset verify on, but you've shown$1not&1. So this doesn't seem to be what you are really running. It would really help if you showed your actual code, not something significantly different.runsql