Run different SQL on multiple DBs using SHELL script

Tags
shell scripts

 
Thread Tools Search this Thread
# 1  
Old 12-19-2013
Run different SQL on multiple DBs using SHELL script

Hi Experts,

I have a list of Dbs.In that DBs i need to execute some sql scripts.
each sql script is unique and it should run on particular DB only.
For example. i have DBs like MDC20V,NDC20V,ODC20V and sql scripts like MD.sql,ND.sql,OD.sql.so MD.sql should run only in MDC20V and ND.sql should run only in NDC20V likewise i have 50+ Dbs.I need a single shell script to run this scripts.
# 2  
Old 12-19-2013
You need to provide some more details - like what database it is & how you're accessing it, where the list of DBs is, where the SQL scripts are, etc.

Just as an example that might help - a very rough (untested) solution, assuming Oracle/SQLPlus, a file with SIDs, and SQL files (only) in a single dir, and the same DB user everywhere:
Code:
SQLDIR=/someplace/sqls
DATADIR=/someplace/data
LOGDIR=/someplace/log
DBUSER=someuser
DBPASSWD=horriblyinsecure

for DBSID in $(< "${DATADIR}/sids.lst" )
do
   SQLPREFIX=$(echo "$DBSID" | cut -c1-2)
   for SQLFILE in "${SQLDIR}/${SQLPREFIX}"*
   do
      sqlplus ${DBUSER}/${DBPASSWD}@${DBSID} <<EOH
set stuff
spool "${LOGDIR}/${SQLFILE}.out"
@${SQLFILE}
quit;
EOH
   done
done


|
Thread Tools Search this Thread
Search this Thread:
Advanced Search

More UNIX and Linux Forum Topics You Might Find Helpful
Run sql query in shell script and output data save as delimited text Jaganjag Shell Programming and Scripting 8 03-26-2017 12:26 PM
Run multiple procedures from shell script parallely Neelkanth Shell Programming and Scripting 11 02-27-2015 01:13 PM
Run a sql script on multiple $Oracle_SID at once and send an alert if reaches the threshold jd_2000 Shell Programming and Scripting 1 02-04-2015 06:39 AM
run sql queries from UNIX shell script. 24ajay Shell Programming and Scripting 1 03-14-2014 05:52 AM
Shell script to run sql query having a long listing of parameters vsachan Shell Programming and Scripting 12 06-03-2013 01:49 PM
Run SQL thru shell script: how to get a new line when run sql query? Kapom Shell Programming and Scripting 2 06-18-2012 11:30 AM
How to run a SQL select query in Oracle database through shell script? vel4ever Shell Programming and Scripting 9 12-21-2011 01:46 PM
Run Sql plus in shell script shekhar2010us Shell Programming and Scripting 8 09-14-2011 02:17 PM
how to execute multiple .sql scripts from within a shell script using sqlplus TRS80 UNIX and Linux Applications 1 05-14-2011 06:50 AM
Help required in passing multiple arguments from a shell script to a pl/sql block ramakanth_burra Shell Programming and Scripting 1 04-07-2011 11:20 AM
How to execute the multiple line sql using shell script girish.raos Shell Programming and Scripting 1 09-01-2009 07:40 AM
shell script to run .sql files balireddy_77 Shell Programming and Scripting 1 03-18-2009 11:17 PM
Executing Multiple .SQL Files from Single Shell Script file anushilrai Shell Programming and Scripting 3 04-07-2008 11:09 AM
How to run an SQL script inside a shell stevefox Shell Programming and Scripting 1 06-15-2006 11:11 PM
How to manage multiple versions of a set of shell and SQL script utilities DennisB Shell Programming and Scripting 2 06-23-2004 09:13 AM