Press "Enter" to skip to content

Simple Shell Script Example To Check If Oracle Database Is Up In Linux / Unix

Check Oracle Database status in bash shell

You want to write a simple shell script in Linux / Unix to check whether Oracle Database is Up or not. The below is the example script which you can write using vi editor. Follow these steps to create and execute a shell script in Linux / Unix.

Run vi editor and add below content by changing values accordingly as mentioned in next paragraph.

#! /bin/bash
echo “select ‘Database is UP and Running!’ db_status from dual;” | sqlplus -s system/psw
exit 0

Change the ORACLE_SID and ORACLE_HOME variable values to your Oracle database information and change the password also for system user or you can use any other user credential details as you are executing just a simple query from dual. After completing the editing save this file and give a name, for this example we can assume file name as

Now to execute the script “” first you need to make the script executable, so give the following chmod command to make the file executable:

$ chmod u+x

The above command will change the permission for the owner (u) of the file to executable (x) and now you would be able to execute this script as following:


Database is UP and Running!

One Comment

  1. Second Home Yusuf Second Home Yusuf December 22, 2015

    My version


    source /home/oracle/.bash_profile

    export ORACLE_SID

    echo "exit" | /oracle/u01/oracle/product/ -L mysid/[email protected] | grep Connected > /dev/null
    if [ $? -eq 0 ]
    echo "OK – `date`" > /home/oracle/log-check-connection.txt
    echo 'SINTA DB ALERT – Database cannot connect:' `date` | mail -s "DB Alert: Database Connection FAIL!!!" [email protected]il.address
    echo "NOT OK – `date`" > /home/oracle/log-check-connection.txt

Comments are closed.