Shellscripts, SQPlus

Run Script for a List of Databases

Holy big list of databases, DBAtman!“”
How to run same script for a list of databases quickly?

In my case I have same password/user in all databases, but in case you haven’t you can make an internal loop with a similar awk command to retrieve users and passwords from a file.

The list:

$: cat /tmp/dbs.cfg
db01
db02
db03
testdb

The script:

for DBSID in ${*-$(awk -F: '!/^#/ {print $1}' /tmp/dbs.cfg}
do
    print "
        connect user/password@${DBSID}
        @script_to_run.sql
        exit " |
    sqlplus /nolog >> /tmp/output_test.log
done

Na, na, na, na, na, na, na, na, na, na, na, na… DBAtman!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s