我正在尝试执行一个shell脚本,其中带有shell脚本值的变量将传递给sqlplus。但它失败了以下错误,EOF也产生了问题。
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
当我尝试执行时,它只选择一个参数值,我得到的误差
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......
当我单独复制该行
时/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
它获取参数值并插入表中。可能是什么原因。我需要在代码中做些什么改变。请告诉我。
答案 0 :(得分:1)
$loc_bkp1
将为空,因为当您尝试设置它时,命名不一致。你可以从$check_fold_size_bkp1
获得:{/ p>
check_fold_size_bkp1=`du -h /archive/node1/bkp/HRMIS_NODE1_PRODFULL_$yr_bkp1$mo_bkp1$dt_bkp1`
但是当你得到接下来的两个变量时,你引用的是$check
,而不是$check_fold_size_bkp1
。所以看起来你想要:
size_bkp1=$(echo $check_fold_size_bkp1 | head -n1 | awk '{print $1;}')
loc_bkp1=$(echo $check_fold_size_bkp1 | head -n1 | awk '{print $2;}')
你也可以考虑用双引号括起参数,以防万一最后结束空白;我还建议您使用-s
和-l
标志来隐藏SQL * Plus标题,如果无法连接到数据库则退出:
/oracle_ee/sqlplus -s -l DBA_SCHEMA/... @.../test.sql "$loc_bkp1" "$clnt_cnt1"
在您的示例代码中,EOF“heredoc”似乎完全是多余的。