开发者

SQL*Plus return code when invalid username or password

I am trying to develop an ANT script that calls SQL*Plus and executes a SQL file. Using the following:

<exec executable="sqlplus" failonerror="true">
    <arg value="-LOGON"/>
    <arg value="scott/${db.pwdapps}"/>
    <arg value="@${scm.target}/install/sql/XXCUST_COMMON_PKG.pks"/>
</exec>

This works b开发者_运维知识库ut when the username or password is incorrectly supplied, SQL*Plus returns with status of success and hence ANT returns the same.

Anyone know how to make SQLPlus return an error status when the username or password is incorrect?


sqlplus /nolog
SQL*Plus: Release 10.2.0.4.0 - Production on Thu Apr 14 08:48:07 2011
Copyright (c) 1982, 2007, Oracle.  All Rights Reserved.
SQL> whenever sqlerror exit failure
SQL> connect ronr/wrongpwd
ERROR:
ORA-01017: invalid username/password; logon denied
echo $?
1

Convert the script to use a here document, or have the script to do the connect after setting the sqlerror and pass the connect info as arguments for the script.


A small upgrade to the @ik_zelf proposal. The solution /nolog works but limit the print of sqlplus, so that if you need logs of the operation performed are not written correctly.

In the man of sqlplus I found the -l parameter that, in case of wrong password, blocks the script, returns error and exit to command prompt:

C:\>sqlplus -l test/test@host

SQL*Plus: Release 12.1.0.2.0 Production on Mar Gen 15 15:27:23 20019
Copyright (c) 1982, 2014, Oracle. All rights reserved.
ERROR:
ORA-01017: invalid username/password; logon denied
SP2-0751: Unable to connect to Oracle. Exiting SQL*Plus    
C:\>


USERPSW=ronr/wrongpwd

KEY='error'

RETCODE=0

newobjs=$(sqlplus -s << EOF ${USERPSW} EOF)

if [[ echo $newobjs | grep -ic "$KEY" -gt 0 ]] then RETCODE=1 else RETCODE=0 fi

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜