oracle-databaseshelldbca

DBCA cannot be run as root


I'm trying automate DBCA to create a new database. I'm using the box bseller/oracle-standard with Vagrant.

provision.sh

#!/bin/bash
echo 'Import environment variables'
env=$( grep -ic "ORACLE_SID" /etc/profile )
if [ ! $env -eq 1 ] ; then
    echo export ORACLE_SID=mydatabase >> /etc/profile
    echo export ORACLE_BASE=/u01/app/oracle >> /etc/profile
    echo export ORACLE_HOME=/u01/app/oracle/product/11.2/dbhome_1 >> /etc/profile
    source /etc/profile
    echo export PATH=$PATH:$ORACLE_HOME/bin >> /etc/profile
fi

echo "Connect with user ORACLE"
sudo su -l oracle

echo "Loading environment variables"
source /etc/profile

echo 'Create database mydatabase'
if [ ! -d /u01/app/oracle/oradata/mydatabase ] ; then
    dbca -silent -createDatabase -templateName General_Purpose.dbc -gdbName mydatabase -sysPassword mypassword -systemPassword mypassword -scriptDest /u01/app/oracle/oradata/mydatabase -characterSet WE8ISO8859P1
fi

But this script doesn't worked:

$ sh provision.sh 
Import environment variables
Connect with user ORACLE
Loading environment variables
Create database mydatabase
DBCA cannot be run as root.

Running all lines from provision.sh in command line. worked!


Solution

  • I am wondering that the line below does not work to run the oracle command inside of a shell script:

    sudo su -l oracle
    

    You should wrap your command to get it work:

    su -c "dbca -silent -createDatabase -templateName General_Purpose.dbc -gdbName qualidade -sysPassword password -systemPassword password -scriptDest /u01/app/oracle/oradata/qualidade -characterSet WE8ISO8859P1" -s /bin/sh oracle
    

    I got this solution here: how to run script as another user without password