Don't go that way, unless you can be sure of some enforced rules in your company. There is NO strict relation between instance, database (db_name?) and db_unique_name! you can have a DB called "ORACLE", with two instances "ONE" and "TWO" and db_unique_name "LEFT" without any problem Tom Kyte made som good answers years ago: http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:533422350794 the only way to be sure is connecting to the instance and query v$instance and v$database Of course if you have a ruleset to name instances according to the database (if no cluster) and with digits added per instance, some scrimts similar to yours will work. best regards, Martin On Tue, Jul 24, 2012 at 7:14 PM, Ethan Post <post.ethan@xxxxxxxxx> wrote: > Thanks for all who contributed answers, seems there are no easy answers. > Ideally some of these things would be exposed externally without having to > look into the database. There are things I might like to know before I even > log in with a script. Is it running, is it a standby, is it rac non-rac, > what is the instance name... > Anyway here is what I came up with, this is my > > .get-active-instance-from-database.sh script. Makes use of a couple other > custom scripts. > > . .require.sh DATABASE "${1}" > > .list-all-databases.sh | grep "^${1}$" | while read DATABASE; do > INSTANCE=$(ps -ef | grep "[ora|asm]_smon_${DATABASE}$" | grep -v "grep" > | cut -d"_" -f3) > if [[ -z "${INSTANCE}" ]]; then > i=0 > while (( ${i} < 5 )); do > ((i=i+1)) > INSTANCE=$(ps -ef | grep "[ora|asm]_smon_${DATABASE}${i}$" | grep > -v "grep" | cut -d"_" -f3) > [[ -n "${INSTANCE}" ]] && break > done > fi > done > > if [[ -z ${INSTANCE} ]]; then > .warning.sh "$0" "Failed to map instance to database ${1}. Verify > database is running and in oratab file." > else > echo ${INSTANCE} > fi > > > -- > //www.freelists.org/webpage/oracle-l > -- //www.freelists.org/webpage/oracle-l