Linux Operating System (MOSC)

MOSC Banner

Running a script against all databases running on your servers

edited Feb 22, 2015 6:55PM in Linux Operating System (MOSC) 3 comments

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

Howdy, Stranger!

Log In

To view full details, sign in to My Oracle Support Community.

Register

Don't have a My Oracle Support Community account? Click here to get started.

Category Leaderboard

Top contributors this month

New to My Oracle Support Community? Visit our Welcome Center

MOSC Help Center