How does one write a script to do some work on all DB's?
Submitted by admin on Sat, 2004-08-07 08:18
Body:
All databases on your machine should be listed in the ORATAB file. One can use this information to do processing on all databases on your machine. Look at this example:
#!/bin/ksh ALL_DATABASES=`cat /etc/oratab|grep -v "^#"|grep -v "N$"|cut -f1 -d: -s` for DB in $ALL_DATABASES do unset TWO_TASK export ORACLE_SID=$DB export ORACLE_HOME=`grep "^${DB}:" /etc/oratab|cut -d: -f2 -s` export PATH=$ORACLE_HOME/bin:$PATH echo "---> Database $ORACLE_SID, using home $ORACLE_HOME" sqlplus -s system/${DB}password @<<-EOF select * from global_name; exit; EOF done
NOTE: The terminating 'EOF' should normally be in column 1. The '-' before the first EOF above causes the shell to strip all leading TAB characters (not spaces, only TABs) from that point until (and including the EOF). This lets you indent the code in between using TABs.
»
- Log in to post comments