|
| 1 | +curdir=`cd $(dirname $0) && pwd` |
| 2 | +. /home/oracle/.profile >/dev/null |
| 3 | + |
| 4 | +User=tivoli |
| 5 | +Pass=**** |
| 6 | +SIDs=`ps -ef|grep pmon|grep -v grep|grep -v '+ASM'|awk '{print $NF}'|awk -F'_' '{print $NF}'` |
| 7 | + |
| 8 | +########################################################################## |
| 9 | +### Get install parameters ### |
| 10 | +########################################################################## |
| 11 | +while getopts "s:u:p:" opt; do |
| 12 | +case $opt in |
| 13 | + s) Tns=$OPTARG;; |
| 14 | + u) User=$OPTARG;; |
| 15 | + p) Pass=$OPTARG;; |
| 16 | + ?) echo "Usage: ./config_or_linux.sh -s TNS -u User -p Pass Instance1" |
| 17 | + exit 1;; |
| 18 | +esac |
| 19 | +done |
| 20 | + |
| 21 | +shift $(($OPTIND - 1)) |
| 22 | +Target=$*; |
| 23 | + |
| 24 | +########################################################################## |
| 25 | +### Check if parameter is valid ### |
| 26 | +########################################################################## |
| 27 | + |
| 28 | +# The target specified must be a valid SID |
| 29 | +if [ -z "$Target" ]; then |
| 30 | + Target=$SIDs |
| 31 | +else |
| 32 | + for i in `echo $Target`; do |
| 33 | + echo $SIDs|grep -w $i >/dev/null 2>&1 |
| 34 | + if [ $? -ne 0 ]; then |
| 35 | + echo "The Instance $i you specified doesnot exist, exiting!" |
| 36 | + exit; |
| 37 | + fi |
| 38 | + done |
| 39 | +fi |
| 40 | + |
| 41 | +# if TNS is specified, then only 1 instance can be configured |
| 42 | +if [ -z "$Tns" ]; then |
| 43 | + userTNS=0; |
| 44 | +else |
| 45 | + userTNS=1; |
| 46 | + num=`echo "$Target" | wc -w` |
| 47 | + if [ $num -ge 2 ];then |
| 48 | + echo "You can only config 1 instance at a time if you specify a TNS, exiting" |
| 49 | + exit |
| 50 | + fi |
| 51 | +fi |
| 52 | + |
| 53 | +########################################################################## |
| 54 | +### Judge if database env is ready ### |
| 55 | +########################################################################## |
| 56 | +# Check it is a primary instance |
| 57 | +ps -ef|grep pmon|grep mrp >/dev/null 2>&1 |
| 58 | +if [ $? -eq 0 ]; then |
| 59 | + echo "Standby database, exiting..." |
| 60 | + exit |
| 61 | +fi |
| 62 | + |
| 63 | +# For each instance, check tns,users are all ready |
| 64 | +for i in `echo $Target`;do |
| 65 | + # if user hasnot specify TNS, use tivoli_InsName as TNS |
| 66 | + if [ $userTNS -eq 0 ]; then |
| 67 | + Tns=`echo $i|sed 's/^/tivoli_/g'` |
| 68 | + fi |
| 69 | + |
| 70 | + # check TNS ready |
| 71 | + if [ `echo -n "$Tns"|wc -c` -gt 15 ]; then |
| 72 | + echo "The TNS $Tns for instance $i exceed the max len (15chars)"; |
| 73 | + exit; |
| 74 | + fi |
| 75 | + |
| 76 | + tnsping $Tns | grep "Failed to resolve name" >/dev/null 2>&1 |
| 77 | + if [ $? -eq 0 ];then |
| 78 | + echo "The $Tns cannot be reached! please check tnsnames.ora config!" |
| 79 | + exit; |
| 80 | + fi |
| 81 | + |
| 82 | + #check user and previlege ready |
| 83 | + sqlplus -S $User/$Pass@$Tns >/dev/null <<EOF |
| 84 | + spool $curdir/sql_8888.log |
| 85 | + SET ECHO OFF |
| 86 | + SET HEADING OFF |
| 87 | + SET FEEDBACK OFF |
| 88 | + select INSTANCE_NAME from v\$INSTANCE; |
| 89 | + spool off |
| 90 | + exit |
| 91 | +EOF |
| 92 | + |
| 93 | + cat $curdir/sql_8888.log |
| 94 | + cat $curdir/sql_8888.log 2>/dev/null|grep $i >/dev/null 2>&1 |
| 95 | + if [ $? -ne 0 ];then |
| 96 | + echo "User $User with Pass $Pass for instance $i not exist or not granted, exiting!" |
| 97 | + exit |
| 98 | + fi |
| 99 | + rm $curdir/sql_8888.log |
| 100 | + |
| 101 | +done |
| 102 | + |
| 103 | +########################################################################## |
| 104 | +### start configuration ### |
| 105 | +########################################################################## |
| 106 | +# |
| 107 | +for i in `echo $Target`;do |
| 108 | + # Judge if the instance has been configured before |
| 109 | + grep "CONFIGSUCCESS" /TIVOLI/IBM/ITM/config/`hostname`_or_$i.cfg >/dev/null 2>&1 |
| 110 | + if [ $? -eq 0 ];then |
| 111 | + echo "### $i already configured, do you want to skip it(yes/no)? " |
| 112 | + read skip; |
| 113 | + if [ "$skip" = "yes" ]; then |
| 114 | + echo "Skipping configuration process for $i" |
| 115 | + continue; |
| 116 | + fi |
| 117 | + fi |
| 118 | + |
| 119 | + if [ $userTNS -eq 0 ];then |
| 120 | + Tns=`echo $i|sed 's/^/tivoli_/g'` |
| 121 | + fi |
| 122 | + |
| 123 | + # The real configuration process |
| 124 | + echo "Configuration for $i started: (User=$User, Pass=$Pass, Tns=$Tns)" |
| 125 | + /TIVOLI/IBM/ITM/bin/CandleDBConfig -s $i -i $User@$Tns -p $Pass or |
| 126 | + |
| 127 | + # to Check configuration successful |
| 128 | + grep "CONFIGSUCCESS" /TIVOLI/IBM/ITM/config/`hostname`_or_$i.cfg >/dev/null 2>&1 |
| 129 | + if [ $? -eq 0 ];then |
| 130 | + echo "Configuration for $i successfully !" |
| 131 | + fi |
| 132 | + |
| 133 | +done |
0 commit comments