从属性文件中读取时,无法使用shell脚本建立与数据库的连接

时间:2016-03-16 15:38:34

标签: database shell

我正在尝试从属性文件中读取并尝试连接到shell脚本中的oracle

属性文件:

#  DB Credentials
DbUser=CHRDPK68
DbPwd=CHRDPK68
DbSid=CHRDDPT9
#No Of Days to keep partition for
NO_OF_DAYS=1

Shell脚本:

#!/bin/bash

#reading from properties file
. ./config/PurgeTool.properties

if [ $# -ne 1 ]; then  
 echo "Please enter no days"
 exit 1
fi

echo "Days are: $1"  

user=$DbUser
pwd=$DbPwd
sid=$DbSid

echo $user
echo $pwd
echo $sid   

sqlplus -s user/pwd@sid<<EOF
SET HEAD OFF
SET AUTOPRINT OFF
SET TERMOUT ON
SET SERVEROUTPUT ON

@ ./sql/delete_partition.sql $1

EOF

它给出了以下问题,但属性文件中的变量被正确回显

CHRDPK68 CHRDPK68 CHRDPT9

ERROR:
ORA-01017: invalid username/password; logon denied


SP2-0306: Invalid option.
Usage: CONN[ECT] [{logon|/|proxy} [AS {SYSDBA|SYSOPER|SYSASM}] [edition=value]]
where <logon> ::= <username>[/<password>][@<connect_identifier>]
      <proxy> ::= <proxyuser>[<username>][/<password>][@<connect_identifier>]
SP2-0306: Invalid option.
Usage: CONN[ECT] [{logon|/|proxy} [AS {SYSDBA|SYSOPER|SYSASM}] [edition=value]]
where <logon> ::= <username>[/<password>][@<connect_identifier>]
      <proxy> ::= <proxyuser>[<username>][/<password>][@<connect_identifier>]
SP2-0157: unable to CONNECT to ORACLE after 3 attempts, exiting SQL*Plus
Have executed the script

但是在用以下代码替换sql行时

sqlplus -s CHRDPK68/CHRDPK68@CHRDPT9<<EOF

它正在成功执行.sql脚本 我确实尝试了所有permu和combo,认为它可能与word是字符串,但没有运气包含在单引号,双引号但仍然错误仍然相同

1 个答案:

答案 0 :(得分:0)

看起来问题就在这里:

sqlplus -s user/pwd@sid<<EOF
...

正确的方法是:

sqlplus -s ${user}/${pwd}@${sid}<<EOF