[英]SQLPLUS not working if I pass variables to Shell Script
I wrote a sample shell script trying to execute a SQL file using SQLPLUS. 我编写了一个示例Shell脚本,尝试使用SQLPLUS执行SQL文件。
Here is my shell script 这是我的shell脚本
#!/bin/bash
username=$1
password=$2
TNS_entry=$3
schema_version=$(sqlplus -S '$username/$password@$TNS_entry' @schema.sql)
echo "Schema_number: $schema_version";
#./schema.sh username password '(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)
(HOST=SANDBOX.domain)(PORT=1521))(CONNECT_DATA=(SERVER=DEDICATED)
(SERVICE_NAME=orcl))'
After executing this I am getting below SQLPLUS error. 执行完此操作后,我得到以下SQLPLUS错误。
Schema_number: ERROR:
ORA-12154: TNS:could not resolve the connect identifier specified
ERROR:
ORA-12162: TNS:net service name is incorrectly specified
ERROR:
ORA-12162: TNS:net service name is incorrectly specified
However if I run this manually I can connect to Oracle DB with out any issues, that concludes my SQLPLUS connection string has no issues. 但是,如果我手动运行此程序,则可以毫无问题地连接到Oracle DB,这表明我的SQLPLUS连接字符串没有问题。 I am guessing shell is the culprit here, but couldn't figure out where it causing issue. 我猜壳是这里的罪魁祸首,但无法弄清楚它在哪里引起问题。
sqlplus username/password@'(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=SANDBOX.domain)(PORT=1521))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=orcl)))' @schema.sql
SQL*Plus: Release 12.2.0.1.0 Production on Wed Mar 14 21:07:37 2018
Copyright (c) 1982, 2016, Oracle. All rights reserved.
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
Can some one take a look at this and help me identify the issue. 有人可以看看这一点,并帮助我确定问题所在。
Thanks and Regards 谢谢并恭祝安康
Saint 圣
I got this working by editing as below. 我通过如下编辑进行工作。 shell acting weird to parse quotes. shell奇怪地解析引号。 Not sure this is ideal solution but this hack served the purpose. 不确定这是否是理想的解决方案,但此hack确实达到了目的。
#!/bin/bash
username=$1
password=$2
TNS_entry=$3
schema_version=$(sqlplus -S ''"$username'"/'"$password'"@'"$TNS_entry'"' @schema.sql)
echo "Schema_number: $schema_version";
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.