I do get a simple question, but i can't fix it..., hope you can help me!
But, this is related to bash script with sqlplus ! thx.
I got this script:
- Code: Select all
#!/bin/bash
#
RM="rm -f"
RMDIR="rm -rf"
LS="ls -l"
MV="mv"
TOUCH="touch"
TESTTOUCH="echo touch"
TESTMV="echo mv"
TESTRM=$LS
TESTRMDIR=$LS
SUCCESS=0
FAILURE=1
TEST=0
HOSTNAME=`hostname`
ORAENV="oraenv"
TODAY=`date +%Y%m%d`
ORIGPATH=/usr/local/bin:$PATH
ORIGLD=$LD_LIBRARY_PATH
export PATH=$ORIGPATH
# Function used to get database parameter values.
f_getparameter(){
if [ -z "$1" ]; then
return
fi
PARAMETER=$1
sqlplus -s -l /nolog <<EOF | awk -F= "/^a=/ {print \$2}"
conn / as sysdba
set head off pagesize 0 feedback off linesize 200
whenever sqlerror exit 1
select 'a='||value from v\$parameter where name = '$PARAMETER';
EOF
}
# Check for the oratab file.
if [ -f /var/opt/oracle/oratab ]; then
ORATAB=/var/opt/oracle/oratab
elif [ -f /etc/oratab ]; then
ORATAB=/etc/oratab
else
echo "ERROR: Could not find oratab file."
exit $FAILURE
fi
# Build list of distinct Oracle Home directories.
OH=`egrep -i ":Y|:N" $ORATAB | grep -v "^#" | grep -v "\*" | cut -d":" -f2 | sort | uniq`
# Exit if there are not Oracle Home directories.
if [ -z "$OH" ]; then
echo "No Oracle Home directories to clean."
exit $SUCCESS
fi
# Get the list of running databases.
SIDS=`ps -e -o args | grep pmon | grep -v grep | awk -F_ '{print $3}' | sort`
# Gather information for each running database.
for ORACLE_SID in `echo $SIDS`
do
# Set the Oracle environment.
ORAENV_ASK=NO
export ORACLE_SID
. $ORAENV
if [ $? -ne 0 ]; then
echo "Could not set Oracle environment for $ORACLE_SID."
else
export LD_LIBRARY_PATH=$ORACLE_HOME/lib:$ORIGLD
ORAENV_ASK=YES
echo "ORACLE_SID: $ORACLE_SID"
# Get the audit_file_dest.
ADUMPDEST=`f_getparameter audit_file_dest`
echo " Audit Dump Dest: $ADUMPDEST"
if [ ! -z "$ADUMPDEST" ] && [ -d "$ADUMPDEST" 2>/dev/null ]; then
ADUMPDIRS="$ADUMPDIRS $ADUMPDEST"
fi
fi
done
The questions is, the script get all the SID into "SIDS"
# Get the list of running databases.
SIDS=`ps -e -o args | grep pmon | grep -v grep | awk -F_ '{print $3}' | sort`
But..., when it try to get each db's Audit Dump Dest, it always only get first SID. The second SID will get nothing, like:
- Code: Select all
[oracle@rac1 Oracle_Script]$ ./test.sh
The Oracle base remains unchanged with value /u01/app/oracle
ORACLE_SID: +ASM1
Audit Dump Dest: /u01/app/11.2.0.3/grid/rdbms/audit
The Oracle base remains unchanged with value /u01/app/oracle
ORACLE_SID: RACHOME
Audit Dump Dest:
[oracle@rac1 Oracle_Script]$