Reputation: 11
I am trying to execute a shell script where variables with values in shell script are getting passed to sqlplus. But it is failing with below error and EOF is creating problem too.
yr_bkp1=$(date +"%Y")
dt_bkp1=$(date +"%d" --date="yesterday")
mn_bkp1=$(date +"%b")
mo_bkp1=$(echo "$mn_bkp1" | tr '[:lower:]' '[:upper:]')
check_fold_size_bkp1=`du -h /archive/node1/bkp/HRMIS_NODE1_PRODFULL_$yr_bkp1$mo_bkp1$dt_bkp1`
size_bkp1=$(echo $check | head -n1 | awk '{print $1;}')
loc_bkp1=$(echo $check | head -n1 | awk '{print $2;}')
cd /archive/node1/bkp/HRMIS_NODE1_PRODFULL_$yr_bkp1$mo_bkp1$dt_bkp1
clnt_cnt1=$(ls -ltr
/archive/node1/bkp/HRMIS_NODE1_PRODFULL_$yr_bkp1$mo_bkp1$dt_bkp1/*.gz | wc -l)
export ORACLE_HOME=/apps/oracle/oracle_ee/product/11.2.0/dbhome
/oracle_ee/sqlplus DBA_SCHEMA/sting23ret@CENTREPO @/rmanbkp/exp_bkp_hpay_essdb/test.sql $loc_bkp1 $clnt_cnt1 <<EOF
EOF
When I am trying to execute it is picking only one argument value I am getting below error
2015
15
JAN
13G /archive/node1/bkp/HRMIS_NODE1_PRODFULL_2015JAN15
296
SQL*Plus: Release 11.2.0.3.0 Production on Fri Jan 16 19:23:01 2015
Copyright (c) 1982, 2011, Oracle. All rights reserved.
Connected to:
Oracle Database 11g Release 11.2.0.3.0 - 64bit Production
With the Real Application Clusters and Automatic Storage Management options
old 1: insert into test (TEST1,TEST2) values ('&1','')
new 1: insert into test (TEST1,TEST2) values ('296','')
1 row created.
Commit complete.
Enter value for 2: old 1: insert into test (TEST1,TEST2) values ('','&2')
new 1: insert into test (TEST1,TEST2) values ('','EOF ')
1 row created.
Commit complete.
Commit complete.
Disconnected from oracle......
When I copy separately the line
/apps/oracle/oracle_ee/product/11.2.0/dbhome/bin/sqlplus LOGIN/PASSWORD@DATABASE @/rmanbkp/scripts/exp_bkp_hpay_essdb_info/exp_bkp_hpay_essdb_ins.sql $loc_bkp1 $clnt_cnt1 <<EOF
it is fetching argument value and inserting to the table. What could be the reason. What change I need to do in the code. Please let me know.
Upvotes: 0
Views: 1929
Reputation: 191235
$loc_bkp1
is going to be empty because you have inconsistent naming when you try to set it. You get $check_fold_size_bkp1
from this:
check_fold_size_bkp1=`du -h /archive/node1/bkp/HRMIS_NODE1_PRODFULL_$yr_bkp1$mo_bkp1$dt_bkp1`
But then when you get the next two variables you refer to $check
, not $check_fold_size_bkp1
. So it looks like you want:
size_bkp1=$(echo $check_fold_size_bkp1 | head -n1 | awk '{print $1;}')
loc_bkp1=$(echo $check_fold_size_bkp1 | head -n1 | awk '{print $2;}')
You might also consider enclosing the arguments in double quotes, in case one ends up blank anyway; and I'd also suggest you use the -s
and -l
flags to hide the SQL*Plus banner and exit if you are unable to connect to the database:
/oracle_ee/sqlplus -s -l DBA_SCHEMA/... @.../test.sql "$loc_bkp1" "$clnt_cnt1"
The EOF 'heredoc' seems completely redundant in your example code.
Upvotes: 1