Oracle Database Connection detection (Shell)
Version 1
Oracle Database Version: Oracle Release 10.2.0.1.0
System Version: Red Hat guest iselinux 5.4
2 detection steps
2.1 write Shell scripts
Edit the check_oracle_connection.sh script for a user with SQLPLUS execution permission.
Vi check_oracle_connection.sh
The Edit content is as follows:
#! /Bin/bash
# Functions: connect oracle server test
# Author: AresKris John
# Modify_date: 2014-11-18.
Mkdir-p/home/gapsv4/log/oracle # create a log storage path
LOG_DIR =/home/gapsv4/log/oracle # log storage path
Rm-rf $ LOG_DIR/* # delete old logs
USERNAME = bodcmp # database USERNAME
PASSWORD = bodcmp # Database PASSWORD
SIDNAME = ora10g # database instance name
Icount = 0
While ["$ icount"-lt 100]
Do
{
Count = 0
While ["$ count"-lt 100]
Do
LOG_FILE = $ LOG_DIR/check_oracle _ $ icount. $ count. log
Echo 'sqlplus $ USERNAME/$ PASSWORD @ $ SIDNAME <EOF
Set echo off
Set feedback off
Spool $ LOG_FILE
Alter session set nls_date_format = 'yyyy-MM-DD: HH24: MI: ss ';
Select sysdate from dual;
Spool off
Set echo on
Set feedback on
Exit
EOF '> $ LOG_FILE
Let count = $ count + 1
Done
}&
Let icount = $ icount + 1
Done
2.2 execute Shell scripts
Directly call bash to execute the check_oracle_connection.sh script.
Bash check_oracle_connection.sh
2.3 script execution Result Analysis
After the script is executed, the Oracle database connection is analyzed based on the script execution results. The situation is as follows:
1. If some logs report connection or query failure errors during execution, the Oracle database connection is unstable and there is a problem.
2. If all logs report connection or query failure errors during execution, it indicates that the Oracle instance or listener process is not started.
3. If no log error is reported during execution, the Oracle database connection is normal and the instance runs normally.