SQLPlus, SQL, Starting & Controlling Oracle Using Shell Scripts

I found a post by dbamac that describes how to run SQLPlus commands and SQL commands themselves from a shell script. I now use a script to start up my Oracle database and bypass my growing frustration with “dbstart” which seems to partially work now that I have set up the correct permissions on the startup.log and shutdown.log files.

As I have said before the way I boot oracle up is by running “sqlplus sys/password as sysdba” then typing “startup” and finally “exit” when it is all booted. I then run a nice long command “emctl stop dbconsole; emctl start dbconsole; lsnrctl start;” to restart the database web console and start the listener service up.

Thanks to dbamac I have now created a short script that does this in one go:

#!/bin/sh
sqlplus sys/password as sysdba <<ENDOFSQL
startup;
exit;
ENDOFSQL
emctl stop dbconsole; emctl start dbconsole; lsnrctl start;

I have to run the script as “oracle” as this is my user created during installation of the Oracle database who has all the right permissions etc. I stored the script as “startupdb” in my $ORACLE_HOME directory, in my case:

$ORACLE_HOME = /export/home/app/oracle/oracle/product/10.2.0/db_1/

So the command I use when I am logged in as root to start everything up is:

su – oracle -c $ORACLE_HOME/startupdb

The power of calling SQLPlus commands from the shell is awesome. It means you can set up cron jobs to automatically email reports, automatically backup data etc etc. Now I just need to get the script to start at boot, which means I am currently digging through the Solaris boot process using websites like this one from Admin’s Choice.

The final goal is to have Oracle automatically start when Solaris boots and then email me to tell me everything is up and running ok. I need to figure out a few things before but it would be an incredibly handy feature to have.

UPDATE:

See this post for how I got Oracle to automatically start on Solaris boot.

3 thoughts on “SQLPlus, SQL, Starting & Controlling Oracle Using Shell Scripts

  1. Pingback: Using Webmin to Start Oracle Automatically on Solaris Boot « James Rossiter

  2. excellent script to start oracle i have put this script in /etc/rc.local to start oracle when system boots up and put the script with shutdown commands in /etc/rc0.d/K01dbshut.. it also shuts down the database during system shutdown… cheers

  3. Pingback: Using Webmin to Start Oracle Automatically on Solaris Boot | James Rossiter

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>