Running a script against all databases running on your servers
Below is a script that always comes in handy when you need to run a specific script against multiple databases running on your server. As long as the ORACLE_SID is in the ORATAB file this should run without any prompts for a user response when setting up the environment. Also, be sure to update the shebang on line 1 to point to the location where ksh is on your server.
#!/bin/ksh
export ORAENV_ASK=NO
ps -eo args|grep smon|egrep -v "ASM|grep|osysmond"|cut -f3 -d_|sort| while read ORASID
do
export ORACLE_SID=${ORASID}
. oraenv
print "${ORACLE_SID}::${ORACLE_HOME}"
${ORACLE_HOME}/bin/sqlplus -S /nolog << EOF
conn / as sysdba
-- Add your commands here.
EOF
print
done