Skip to content

Commit 654466a

Browse files
committed
added dbshut and start scripts, sanitized oracle, and dbstart and shut scripts
1 parent f7c1c67 commit 654466a

File tree

2 files changed

+678
-0
lines changed

2 files changed

+678
-0
lines changed
Lines changed: 224 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,224 @@
1+
#!/bin/sh
2+
#
3+
# $Id: dbshut.sh 22-may-2008.05:19:31 arogers Exp $
4+
# Copyright (c) 1991, 2008, Oracle. All rights reserved.
5+
#
6+
7+
###################################
8+
#
9+
# usage: dbshut $ORACLE_HOME
10+
#
11+
# This script is used to shutdown ORACLE from /etc/rc(.local).
12+
# It should ONLY be executed as part of the system boot procedure.
13+
#
14+
# This script will shutdown all databases listed in the oratab file
15+
# whose third field is a "Y" or "W". If the third field is set to "Y" and
16+
# there is no ORACLE_SID for an entry (the first field is a *),
17+
# then this script will ignore that entry.
18+
#
19+
# This script requires that ASM ORACLE_SID's start with a +, and
20+
# that non-ASM instance ORACLE_SID's do not start with a +.
21+
#
22+
# Note:
23+
# Use ORACLE_TRACE=T for tracing this script.
24+
# Oracle Net Listener is also shutdown using this script.
25+
#
26+
# The progress log for each instance shutdown is logged in file
27+
# $ORACLE_HOME/shutdown.log.
28+
#
29+
# On all UNIX platforms except SOLARIS
30+
# ORATAB=/etc/oratab
31+
#
32+
# To configure, update ORATAB with Instances that need to be shutdown
33+
# Entries are of the form:
34+
# $ORACLE_SID:$ORACLE_HOME:<N|Y>:
35+
# An example entry:
36+
# main:/usr/lib/oracle/emagent_10g:Y
37+
#
38+
#####################################
39+
LISTNER_NAME=LISTNER
40+
41+
trap 'exit' 1 2 3
42+
case $ORACLE_TRACE in
43+
T) set -x ;;
44+
esac
45+
46+
# Set path if path not set (if called from /etc/rc)
47+
SAVE_PATH=/bin:/usr/bin:/etc:${PATH} ; export PATH
48+
SAVE_LLP=$LD_LIBRARY_PATH
49+
50+
# The this to bring down Oracle Net Listener
51+
ORACLE_HOME_LISTNER=$1
52+
if [ ! $ORACLE_HOME_LISTNER ] ; then
53+
echo "ORACLE_HOME_LISTNER is not SET, unable to auto-stop Oracle Net Listener"
54+
echo "Usage: $0 ORACLE_HOME"
55+
else
56+
LOG=$ORACLE_HOME_LISTNER/listener.log
57+
58+
# Set the ORACLE_HOME for the Oracle Net Listener, it gets reset to
59+
# a different ORACLE_HOME for each entry in the oratab.
60+
export ORACLE_HOME=$ORACLE_HOME_LISTNER
61+
62+
# Stop Oracle Net Listener
63+
if [ -f $ORACLE_HOME_LISTNER/bin/tnslsnr ] ; then
64+
echo "$0: Stoping Oracle Net Listener" >> $LOG 2>&1
65+
$ORACLE_HOME_LISTNER/bin/lsnrctl stop $LISTNER_NAME >> $LOG 2>&1 &
66+
else
67+
echo "Failed to auto-stop Oracle Net Listener using $ORACLE_HOME_LISTNER/bin/tnslsnr"
68+
fi
69+
fi
70+
71+
# Set this in accordance with the platform
72+
ORATAB=/etc/oratab
73+
if [ ! $ORATAB ] ; then
74+
echo "$ORATAB not found"
75+
exit 1;
76+
fi
77+
78+
# Stops an instance
79+
stopinst() {
80+
ORACLE_SID=`echo $LINE | awk -F: '{print $1}' -`
81+
if [ "$ORACLE_SID" = '*' ] ; then
82+
ORACLE_SID=""
83+
fi
84+
# Called programs use same database ID
85+
export ORACLE_SID
86+
ORACLE_HOME=`echo $LINE | awk -F: '{print $2}' -`
87+
# Called scripts use same home directory
88+
export ORACLE_HOME
89+
# Put $ORACLE_HOME/bin into PATH and export.
90+
PATH=$ORACLE_HOME/bin:${SAVE_PATH} ; export PATH
91+
# add for bug 652997
92+
LD_LIBRARY_PATH=${ORACLE_HOME}/lib:${SAVE_LLP} ; export LD_LIBRARY_PATH
93+
PFILE=${ORACLE_HOME}/dbs/init${ORACLE_SID}.ora
94+
95+
# See if it is a V6 or V7 database
96+
VERSION=undef
97+
if [ -f $ORACLE_HOME/bin/sqldba ] ; then
98+
SQLDBA=sqldba
99+
VERSION=`$ORACLE_HOME/bin/sqldba command=exit | awk '
100+
/SQL\*DBA: (Release|Version)/ {split($3, V, ".") ;
101+
print V[1]}'`
102+
case $VERSION in
103+
"6") ;;
104+
*) VERSION="internal" ;;
105+
esac
106+
else
107+
if [ -f $ORACLE_HOME/bin/svrmgrl ] ; then
108+
SQLDBA=svrmgrl
109+
VERSION="internal"
110+
else
111+
SQLDBA="sqlplus /nolog"
112+
fi
113+
fi
114+
115+
case $VERSION in
116+
"6") sqldba command=shutdown ;;
117+
"internal") $SQLDBA <<EOF
118+
connect internal
119+
shutdown immediate
120+
EOF
121+
;;
122+
*) $SQLDBA <<EOF
123+
connect / as sysdba
124+
shutdown immediate
125+
quit
126+
EOF
127+
;;
128+
esac
129+
130+
if test $? -eq 0 ; then
131+
echo "${INST} \"${ORACLE_SID}\" shut down."
132+
else
133+
echo "${INST} \"${ORACLE_SID}\" not shut down."
134+
fi
135+
}
136+
137+
#
138+
# Loop for every entry in oratab file and and try to shut down
139+
# that ORACLE
140+
#
141+
# Following loop shuts down 'Database Instance[s]' with 'Y' entry
142+
143+
cat $ORATAB | while read LINE
144+
do
145+
case $LINE in
146+
\#*) ;; #comment-line in oratab
147+
*)
148+
ORACLE_SID=`echo $LINE | awk -F: '{print $1}' -`
149+
if [ "$ORACLE_SID" = '*' ] ; then
150+
# NULL SID - ignore
151+
ORACLE_SID=""
152+
continue
153+
fi
154+
# Proceed only if last field is 'Y' or 'W'
155+
if [ "`echo $LINE | awk -F: '{print $NF}' -`" = "Y" ] ; then
156+
if [ `echo $ORACLE_SID | cut -b 1` != '+' ]; then
157+
INST="Database instance"
158+
ORACLE_HOME=`echo $LINE | awk -F: '{print $2}' -`
159+
LOG=$ORACLE_HOME/shutdown.log
160+
echo "Processing $INST \"$ORACLE_SID\": log file $LOG"
161+
stopinst >> $LOG 2>&1
162+
fi
163+
fi
164+
;;
165+
esac
166+
done
167+
168+
#
169+
# Following loop shuts down 'Database Instance[s]' with 'W' entry
170+
#
171+
cat $ORATAB | while read LINE
172+
do
173+
case $LINE in
174+
\#*) ;; #comment-line in oratab
175+
*)
176+
ORACLE_SID=`echo $LINE | awk -F: '{print $1}' -`
177+
if [ "$ORACLE_SID" = '*' ] ; then
178+
# NULL SID - ignore
179+
ORACLE_SID=""
180+
continue
181+
fi
182+
# Proceed only if last field is 'Y' or 'W'
183+
if [ "`echo $LINE | awk -F: '{print $NF}' -`" = "W" ] ; then
184+
if [ `echo $ORACLE_SID | cut -b 1` != '+' ]; then
185+
INST="Database instance"
186+
ORACLE_HOME=`echo $LINE | awk -F: '{print $2}' -`
187+
LOG=$ORACLE_HOME/shutdown.log
188+
echo "Processing $INST \"$ORACLE_SID\": log file $LOG"
189+
stopinst >> $LOG 2>&1
190+
fi
191+
fi
192+
;;
193+
esac
194+
done
195+
196+
#
197+
# Following loop shuts down 'ASM Instance[s]'
198+
#
199+
200+
cat $ORATAB | while read LINE
201+
do
202+
case $LINE in
203+
\#*) ;; #comment-line in oratab
204+
*)
205+
ORACLE_SID=`echo $LINE | awk -F: '{print $1}' -`
206+
if [ "$ORACLE_SID" = '*' ] ; then
207+
# NULL SID - ignore
208+
ORACLE_SID=""
209+
continue
210+
fi
211+
# Proceed only if last field is 'Y'.
212+
# Entries whose last field is not Y or N are not DB entry, ignore them.
213+
if [ "`echo $LINE | awk -F: '{print $NF}' -`" = "Y" ] ; then
214+
if [ `echo $ORACLE_SID | cut -b 1` = '+' ]; then
215+
INST="ASM instance"
216+
ORACLE_HOME=`echo $LINE | awk -F: '{print $2}' -`
217+
LOG=$ORACLE_HOME/shutdown.log
218+
echo "Processing $INST \"$ORACLE_SID\": log file $LOG"
219+
stopinst >> $LOG 2>&1
220+
fi
221+
fi
222+
;;
223+
esac
224+
done

0 commit comments

Comments
 (0)