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.
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:
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