Choose Oracle SID and HOME from oratab OR From Dynamic LSOF Output.
Tested On
Red Hat Enterprise Linux Server release 6.5 (Santiago)
Oracle EE 11.2.0.3/11.2.0.4/12.1.0.2
#!/bin/bash
#kamil.piorekk@gmail.com
echo "Choose input: 1>oratab 2>dynamic-lsof"
read choose
case $choose in
1)
#-------------------------------------------------------------------------------------
declare -A arr
x=0
for i in `cat /etc/oratab | grep -v '^#' | grep : | awk {'print $1'}`
do
x=`expr $x + 1`
sid=`echo $i | cut -d':' -f1`
home=`echo $i | cut -d':' -f2`
#arr[$x,1,1]=$sid
#arr[$x,1,2]=$home
arr[$x,1]=$sid
arr[$x,2]=$home
printf "$x %10s %s\n" ${arr[$x,1]} ${arr[$x,2]}
done
echo "Enter: {1-"$x"}"
read x
export ORACLE_SID=${arr[$x,1]}
export ORACLE_HOME=${arr[$x,2]}
touch "/tmp/oracleenvvar.tmp"
echo "export ORACLE_SID=${arr[$x,1]}" > /tmp/oracleenvvar.tmp
echo "export ORACLE_HOME=${arr[$x,2]}" >> /tmp/oracleenvvar.tmp
echo "export PATH=${arr[$x,2]}/bin:/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin" >> /tmp/oracleenvvar.tmp
echo "export ORACLE_BASE=" >> /tmp/oracleenvvar.tmp
echo "export LD_LIBRARY_PATH=${arr[$x,2]}/lib" >> /tmp/oracleenvvar.tmp
source /tmp/oracleenvvar.tmp
#rm -f "/tmp/oracleenvvar.tmp"
echo "Chosen ORACLE_SID:> "$ORACLE_SID" ORACLE_HOME:> "$ORACLE_HOME
#echo "ORACLE_SID> "$ORACLE_SID
#echo "ORACLE_HOME> "$ORACLE_HOME
x=0
;;
2)
echo > /tmp/oratab_dynamic
for i in `lsof | grep "lk" | awk {'print $9'} | sort | uniq | grep dbs`
do
delimit=`echo $i | sed 's/[^/]//g' | awk '{ print length }'`
delimits=`expr $delimit + 1`
delimith=`expr $delimit - 1`
sid=`echo $i | cut -d'/' -f$delimits | awk '{print tolower($0)}'`
allstringlength_i=`expr length $i`
sidlength_i_2=`expr length $sid`
allstringlength_i_3=`expr $allstringlength_i - $sidlength_i_2 - 5`
home=`echo $i | awk '{print tolower($0)}'`
sid=`echo ${sid:2}`
home=`echo ${home:0:$allstringlength_i_3}`
echo $sid":"$home":N" >> /tmp/oratab_dynamic
#awk {'print $sid":"$home'}
done
#-------------------------------------------------------------------------------------
declare -A arr
x=0
for i in `cat /tmp/oratab_dynamic | grep -v '^#' | grep : | awk {'print $1'}`
do
x=`expr $x + 1`
sid=`echo $i | cut -d':' -f1`
home=`echo $i | cut -d':' -f2`
#arr[$x,1,1]=$sid
#arr[$x,1,2]=$home
arr[$x,1]=$sid
arr[$x,2]=$home
printf "$x %10s %s\n" ${arr[$x,1]} ${arr[$x,2]}
done
echo "Enter: {1-"$x"}"
read x
export ORACLE_SID=${arr[$x,1]}
export ORACLE_HOME=${arr[$x,2]}
touch "/tmp/oracleenvvar.tmp"
echo "export ORACLE_SID=${arr[$x,1]}" > /tmp/oracleenvvar.tmp
echo "export ORACLE_HOME=${arr[$x,2]}" >> /tmp/oracleenvvar.tmp
echo "export PATH=${arr[$x,2]}/bin:/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin" >> /tmp/oracleenvvar.tmp
echo "export ORACLE_BASE=" >> /tmp/oracleenvvar.tmp
echo "export LD_LIBRARY_PATH=${arr[$x,2]}/lib" >> /tmp/oracleenvvar.tmp
source /tmp/oracleenvvar.tmp
#rm -f "/tmp/oracleenvvar.tmp"
echo "Chosen ORACLE_SID:> "$ORACLE_SID" ORACLE_HOME:> "$ORACLE_HOME
#echo "ORACLE_SID> "$ORACLE_SID
#echo "ORACLE_HOME> "$ORACLE_HOME
x=0
;;
esac
Regards
kamil.piorekk@gmail.com
Komentarze
Prześlij komentarz