Simple Shell Script Example To Check If Oracle Database Is Up In Linux / Unix
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.
echo “select ‘Database is UP and Running!’ db_status from dual;” | sqlplus -s system/psw
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 isdbup.sh.
Now to execute the script “isdbup.sh” first you need to make the script executable, so give the following chmod command to make the file executable:
$ chmod u+x isdbup.sh
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!