使用 bash 变量时 Sqlplus 登录错误:SP2-0306: Invalid option

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6550542/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 20:43:17  来源:igfitidea点击:

Sqlplus login error when using bash variables: SP2-0306: Invalid option

oraclebashsqlplusora-01017

提问by rsinuhe

I have a bash script that connects to an oracle 10g database.

我有一个连接到 oracle 10g 数据库的 bash 脚本。

In a first step it takes some variables from a "config" file with the following command

在第一步中,它使用以下命令从“配置”文件中获取一些变量

. /path/to/my/configfile.ini

In the config file there are some variables:

在配置文件中有一些变量:

export USRID=myUser
export USRID_PASS=myPassword
export USR_PASS="$USRID/$USRID_PASS@myDatabase"

Then it actually connects through sqlplus using the command:

然后它实际上使用以下命令通过 sqlplus 连接:

sqlplus -s $usr_pass

Terrible Security and Design issues aside (this script has been around for 5 years). This is actually doing its job in one of our UNIX servers, but not in another.

撇开可怕的安全和设计问题不谈(这个脚本已经存在 5 年了)。这实际上是在我们的一台 UNIX 服务器上完成它的工作,但在另一台服务器上却没有。

When I run the script with bash -x, I can see that the command expanded to:

当我用 运行脚本时bash -x,我可以看到命令扩展为:

sqlplus -s myUser/myPassword@myDatabase

...which should do fine (and is actually working in one server), but the response in the failing server is:

...这应该很好(并且实际上在一台服务器上工作),但故障服务器的响应是:

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

SP2-0306: Invalid option. Usage: CONN[ECT] [logon] [AS {SYSDBA|SYSOPER}] where ::= [/][@] | SP2-0306: Invalid option.

错误:ORA-01017:用户名/密码无效;登录被拒绝

SP2-0306:无效选项。用法:CONN[ECT] [登录] [AS {SYSDBA|SYSOPER}] where ::= [/][@] | SP2-0306:无效选项。

I'm guessing it has to do more with bash than with oracle, but I'm no bash expert. Is there some configuration or detail I'm missing?

我猜它对 bash 的作用比用 oracle 多,但我不是 bash 专家。是否有我遗漏的一些配置或细节?

EDIT:

编辑:

Trying to pin down the problem a bit more, I'm now running two versions of the script in a third development server, and in different tests, the login works if i do it with:

试图进一步确定问题,我现在在第三个开发服务器中运行脚本的两个版本,并且在不同的测试中,如果我这样做,登录可以工作:

sqlplus -s $usrid/$usrid_pass@myDatabase

but not when i try:

但不是当我尝试:

sqlplus -s $usr_pass

So its a bit annoying.

所以它有点烦人。

Besides that, i'll have to check on te config file synchronization process... I'll let you know when i get to something new. Thanks everybody.

除此之外,我必须检查配置文件同步过程...当我有新的东西时,我会告诉你。谢谢大家。

回答by DCookie

The message is pretty clear:

该消息非常清楚:

  • you've successfully contacted a database
  • the credentials supplied are wrong
  • 你已经成功联系了一个数据库
  • 提供的凭据错误

This indicates there isn't really anything wrong with your client configuration.

这表明您的客户端配置没有任何问题。

So, that leaves you with

所以,这给你留下了

  • the user/pw combination is wrong
  • you've not contacted the database you think you have
  • 用户/密码组合错误
  • 您尚未联系您认为拥有的数据库

Possibilites:

可能性:

  • Make sure you can connect with the credentials supplied from the command line.
  • Use tnsping mydatabase to check the host and instance you're contacting, verify it's correct. Output from this command should tell you the host, port, and instance/service you're connecting to. If it's wrong, check the tnsnames.ora file for this alias.
  • As @OMG Ponies suggests, if you're using 11g, make sure the case in your passwords is correct
  • 确保您可以使用命令行提供的凭据进行连接。
  • 使用 tnsping mydatabase 检查您正在联系的主机和实例,验证它是否正确。此命令的输出应告诉您要连接的主机、端口和实例/服务。如果错误,请检查 tnsnames.ora 文件中是否有此别名。
  • 正如@OMG Ponies 所建议的,如果您使用的是 11g,请确保您的密码大小写正确

回答by Darius

This worked for me: connect user/"password" I think if the password contains special characters like '@' we need to use "" for the password.

这对我有用:连接用户/“密码”我认为如果密码包含像“@”这样的特殊字符,我们需要使用“”作为密码。

回答by Subrata Nath

I solved this problem on my mac machine by changing the shell to 'sh' from 'bash'. Everything just worked smooth then.

我通过将 shell 从 'bash' 更改为 'sh' 在我的 mac 机器上解决了这个问题。那时一切都很顺利。

Thanks to the original reporter of the problem who explained with a good hint.

感谢问题的原记者,他解释得很好。

回答by Gary Myers

Daft question, but are you sure you are using the bashshell on both unix servers ?

愚蠢的问题,但你确定你bash在两个 unix 服务器上都使用shell 吗?

I'd try replacing

我会尝试更换

export USR_PASS="$USRID/$USRID_PASS@myDatabase"

with export USR_PASS="${USRID}/${USRID_PASS}@myDatabase"

导出 USR_PASS="${USRID}/${USRID_PASS}@myDatabase"

to make sure the variables get interpreted correctly

确保变量得到正确解释

As a final, exotic though, does the password contain any characters other than basic alpha-numeric and punctuation. Because 10g isn't case sensitive, a lowercase password gets converted to uppercase, which can cause odd effects with things like accented characters

作为最后的,奇特的,密码是否包含除基本字母数字和标点符号以外的任何字符。因为 10g 不区分大小写,小写密码会转换为大写,这可能会导致重音字符等奇怪的效果