简体   繁体   English

通过使用 getopts 将凭据作为参数传递,无法从 linux 连接到 sqlplus

[英]Not able to connect to sqlplus from linux by passing credentials as parameter using getopts

I am trying to connect sqlplus by passing credentials as a parameter using getopts method-我正在尝试通过使用 getopts 方法将凭据作为参数传递来连接 sqlplus-

Code:代码:

while getopts ":o:s:t::i::p::f::" opt; do
  case "$opt" in

    o) uname=$OPTARG ;;
    s) sname=$OPTARG ;;
    t) password=$OPTARG ;;
    i) ip=$OPTARG ;;
    p) port=$OPTARG;;
    f) sid=$OPTARG;;
    ?) echo "I Don't Know What $OPTARG it is"
  esac
done
sqlplus -silent $uname/$password@$ip:$port/$sid

N when I am running this script as - N 当我运行这个脚本时 -

../a.sh -o otv4 -s OTV4 -t Password12356/$ -i 10.10.98.6 -p 1521 -f ortf

Its giving me Output something like this-它给了我 Output 这样的东西-

***
SQL*Plus: Release 18.0.0.0.0 - Production Version 18.3.0.0.0

Copyright (c) 1982, 2018, Oracle.  All rights reserved.

Use SQL*Plus to execute SQL, PL/SQL and SQL*Plus statements.

Usage 1: sqlplus -H | -V

    -H             Displays the SQL*Plus version and the
                   usage help.
    -V             Displays the SQL*Plus version.

Usage 2: sqlplus [ [<option>] [{logon | /nolog}] [<start>] ]

  <option> is: [-AC] [-C <version>] [-F] [-L] [-M "<options>"] [-NOLOGINTIME]
               [-R <level>] [-S]

    -AC            Enable Application Continuity.
    -C <version>   Sets the compatibility of affected commands to the
                   version specified by <version>.  The version has
                   the form "x.y[.z]".  For example, -C 10.2.0
    -F             This option improves performance in general. It changes
                   the default values settings.
                   See SQL*Plus User's Guide for the detailed settings.
    -L             Attempts to log on just once, instead of
                   reprompting on error.
    -M "<options>" Sets automatic HTML or CSV markup of output.  The options
***

And not able to connect Sqlplus.并且无法连接Sqlplus。 Can someone please help me with this?!有人可以帮我解决这个问题吗?!

Thanks in advance!提前致谢!

I test your script and it's working fine.我测试了你的脚本,它工作正常。 I find your password contain $ , and it should be escaped with a backslash.我发现您的密码包含$ ,并且应该使用反斜杠对其进行转义。

you can use the next solution to escape the password:您可以使用下一个解决方案来转义密码:

#escape password, store value in password_esc
printf -v password_esc "%q" "$password"
sqlplus -silent $uname/$password_esc@$ip:$port/$sid 
#solution2 (more simpler)
password2=${password@Q}
sqlplus -silent $uname/$password2@$ip:$port/$sid 

A demo online to show how password is escaped.一个在线演示,显示密码是如何转义的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM