-
Notifications
You must be signed in to change notification settings - Fork 1
/
stop-all.sh
executable file
·79 lines (72 loc) · 1.58 KB
/
stop-all.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#!/bin/sh
#
SCRIPTDIR=$(cd $(dirname $0) && pwd)
source $SCRIPTDIR/lib/libcommon.sh
PRINT_USAGE="Usage: $0 [ -r ]"
STOP_RUNNING=0
STOP_ASM=0
FORCE=0
function stop_db {
[ -z "$1" ] && err_exit "stop-db: SID parameter required."
export ORACLE_SID=$1
echo "Stopping database $1 ..."
if [ "$FORCE" -eq 0 ]; then
sqlCommand="shutdown immediate"
else
sqlCommand="shutdown abort"
fi
run_query "$sqlCommand"
echo "Done."
}
while getopts "raf" opt
do
case $opt in
r)
STOP_RUNNING=1
;;
a)
STOP_ASM=1
;;
f)
FORCE=1
;;
\?)
err_exit
;;
esac
done
if [ "$STOP_RUNNING" -eq 1 ]; then
for oraSID in $(ps -ef |grep _pmon |grep -v grep | awk '{print $NF}' | sed -e 's/^.*pmon_//')
do
if [ -n "$(echo $oraSID | sed -e 's/^+.*$//')" ]; then
stop_db $oraSID
fi
done
exit 0
fi
if [ "$STOP_ASM" -eq 1 ]; then
which srvctl 2>&1 >/dev/null
[ $? -ne 0 ] && err_exit "srvctl not found"
for oraSID in $(ps -ef |grep _pmon |grep -v grep | awk '{print $NF}' | sed -e 's/^.*pmon_//')
do
if [ -z "$(echo $oraSID | sed -e 's/^+.*$//')" ]; then
srvctl stop asm -force
fi
done
exit 0
fi
for line in $(sed -e 's/#.*$//' -e '/^$/d' /etc/oratab)
do
homePath=$(echo $line | cut -d: -f2)
if [ -d "$homePath" ]; then
ORACLE_SID=$(echo $line | cut -d: -f1)
if [ -n "$(echo $ORACLE_SID | sed -e 's/^+.*$//')" ]; then
ps -ef | grep pmon_$ORACLE_SID | grep -v grep >/dev/null 2>&1
if [ $? -eq 0 ]; then
stop_db $ORACLE_SID
else
info_msg "Database $ORACLE_SID not running."
fi
fi
fi
done