I was wondering the same thing as I tried to come up with a way to set the ORACLE_SID in a RAC environment. One of my fellow DBAs had a scheme where he looked at the pmon process and extracted the last digit as the instance number, but that only worked if the instance was running. The following is my solution as custom code at the end of oraenv (renamed to oraenvr), that will grab node number as the last digit of the running instance name, or extract the last digit from a running ASM instance. It only needs to do this for non-ASM instances, because with ASM, the database name in /etc/oratab is also the instance name (e.g., +ASM1). But, again, you'll need either the database or ASM instance running so it will have a running process from which to get the node number.
#
# Install any "custom" code here
#
# Add proceeding digit to ORACLE_SID if it's a database instance
#
if [ `expr $ORACLE_SID|cut -c1-4` != "+ASM" ]; then ## ASM instance name is also the /etc/oratab database name, so we don't need to change it.
len=`ps -ef|grep smon|grep $ORACLE_SID|wc -c`
if [ $len != "0" ]; then # we found the running non-ASM database instance
len1=`expr $len - 1`
nodenum=`ps -ef|grep smon|grep $ORACLE_SID|cut -c$len1-$len`
else ## use ASM instance as node number reference since database instance is probably down.
len=`ps -ef|grep smon|grep ASM|wc -c`
len1=`expr $len - 1`
nodenum=`ps -ef|grep smon|grep ASM|cut -c$len1-$len`
fi
ORACLE_SID=$ORACLE_SID$nodenum
fi
Blockquote