Script to autostart dbora

Paste the below code in console:

# Create startup/shutdown script files
mkdir -p /home/oracle/scripts
chown oracle /home/oracle/scripts
cat>>/home/oracle/scripts/startup.sh<<EEOF
#!/bin/bash
# Start Listener
lsnrctl start
# Start Database
sqlplus/assysdba<<EOF
STARTUP;
ALTER PLUGGABLE DATABASE ALL OPEN;
EXIT;
EOF
EEOF
cat>>/home/oracle/scripts/shutdown.sh<<EEOF
#!/bin/bash
# Stop Database
sqlplus/assysdba<<EOF
ALTER PLUGGABLE DATABASE ALL CLOSE IMMEDIATE;
SHUTDOWN IMMEDIATE;
EXIT;
EOF
# Stop Listener
lsnrctl stop
EEOF
# Make them executable
chmodu+x/home/oracle/scripts/startup.sh/home/oracle/scripts/shutdown.sh
chown oracle /home/oracle/scripts/startup.sh/home/oracle/scripts/shutdown.sh
# Create service script
cat>/tmp/dbora<<EOF
#!/bin/sh
# chkconfig: 345 90 25
# description: Oracle auto start-stop script.
#
# Set ORA_OWNER to the user id of the owner of the
# Oracle database software.
ORA_OWNER=oracle
case"$1"in
    'start')
        # Start the Oracle databases:
        # The following command assumes that the oracle login
        # will not prompt the user for any values
        su-$ORA_OWNER-c"/home/oracle/scripts/startup.sh >> /home/oracle/scripts/startup_shutdown.log 2>&1"
        touch/var/lock/subsys/dbora
        ;;
    'stop')
        # Stop the Oracle databases:
        # The following command assumes that the oracle login
        # will not prompt the user for any values
        su-$ORA_OWNER-c"/home/oracle/scripts/shutdown.sh >> /home/oracle/scripts/startup_shutdown.log 2>&1"
        rm-f/var/lock/subsys/dbora
        ;;
esac
EOF
sudo mv/tmp/dbora/etc/init.d/dbora
sudo chownroot./etc/init.d/dbora
# Make the service script executable
sudo chmod750/etc/init.d/dbora
# Associate the service with the appropriate run levels and set it to auto-start using the following command.
sudo chkconfig--add dbora
Advertisements