Skip to Main Content

Oracle Database Discussions

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

How to Spool Data in Shell Script

Rajan SwMay 8 2017 — edited May 8 2017

Hi I have created a script file where I am checking if the particular table is there or not if that table is not there I have to run few .sql files which will create the table ,insert data etc ..

each .sql file has the spool option inside the file but still there is no spooling .

Here is my Shell Script;

#echo "Pleaase enter Oracle_home directory"

v_oracle_home=$1

#echo "Please enter the Oracle_sid"

v_oracle_sid=$2

#echo "Please enter the Database user name"

v_user_name=$3

#echo "Please enter DB password"

v_password=$4

#echo "Enter the base directory for the files Which is the base directory for creating the extract files"

v_new_base_directory=$5

###############################################################################

######################## Check for Environment variable########################

###############################################################################

if [[ ${v_oracle_home} == "" || ${v_oracle_sid} == "" || ${v_user_name} == "" || ${v_password} == ""||${v_new_base_directory} == "" ]]

  then

    echo " Please check the environment variable (ORACLE_HOME or ORACLE_SID or username or password) settings. "

    echo " The proper format would be like filename oracle_home oracle_sid username password base_directory "

    exit 1

  fi

###############################################################################

# Two command line parameters : ORACLE username and password .#

###############################################################################

export ORACLE_HOME=$v_oracle_home

echo $ORACLE_HOME

export ORACLE_SID=$v_oracle_sid

echo $ORACLE_SID

v_table_name=$(sqlplus -S $v_user_name/$v_password << EOF

  set head off

  set feedback off

  set pagesize 5000

  set linesize 30000

  select  table_name from all_tables where table_name='MI_SCHEMA_VERSION' AND owner='ESLTPTADM';

  exit

EOF)

echo "$v_table_name"

if [[ ${v_table_name}  == "" ]];

then

sqlplus -s $v_user_name/$v_password  << EOF

                set echo on

                set define off

                spool create_config_ddl.log

               -

                @/home/oracle/MI_XES_Trunk_DDL.SQL;

                @/home/oracle/MI_XES_Trunk_DML.SQL;

                @/home/oracle/MI_XES_Trunk_PROC.SQL;

                spool off;

                exit;

EOF

fi

Here in Bold  I am executing the .sql files and each .sql file has the spool option at the starting of the files .

I am using Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production.

Will appreciate any thoughts on this , Thanks in advance .

Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jun 5 2017
Added on May 8 2017
9 comments
6,092 views