-
Notifications
You must be signed in to change notification settings - Fork 6
/
checkDBStatus.sh
executable file
·48 lines (43 loc) · 1.23 KB
/
checkDBStatus.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
#!/bin/bash
# LICENSE CDDL 1.0 + GPL 2.0
#
# Copyright (c) 1982-2017 Oracle and/or its affiliates. All rights reserved.
#
# Since: May, 2017
# Author: [email protected]
# Description: Checks the status of Oracle Database.
# The ORACLE_HOME, ORACLE_SID and the PATH has to be set.
#
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
#
# Check that ORACLE_HOME is set
if [ "$ORACLE_HOME" == "" ]; then
script_name=`basename "$0"`
echo "$script_name: ERROR - ORACLE_HOME is not set. Please set ORACLE_HOME and PATH before invoking this script."
exit 3;
fi;
# Check that ORACLE_SID is set
if [ "$ORACLE_SID" == "" ]; then
script_name=`basename "$0"`
echo "$script_name: ERROR - ORACLE_SID is not set. Please set ORACLE_SID before invoking this script."
exit 3;
fi;
# Check Oracle DB status and store it in status
status=`sqlplus -s / as sysdba << EOF
set heading off;
set pagesize 0;
select status from v\\$instance;
exit;
EOF`
# Store return code from SQL*Plus
ret=$?
# SQL Plus execution was successful and database is open
if [ $ret -eq 0 ] && [ "$status" = "OPEN" ]; then
exit 0;
# Database is not open
elif [ "$status" != "OPEN" ]; then
exit 1;
# SQL Plus execution failed
else
exit 2;
fi;