无法使用java代码执行lsnrctr status命令

时间:2017-11-09 09:56:27

标签: ssh

我使用java代码连接远程服务器,但其中一个unix命令未按预期执行。 Unix命令如下:

 /u01/db/oracle/db/tech_st/11.1.0/bin/lsnrctl status VIS

输出:

LSNRCTL for Linux: Version 11.1.0.7.0 - Production on 06-NOV-2017 10:48:10

Copyright (c) 1991, 2008, Oracle.  All rights reserved.

TNS-01101: Message 1101 not found; No message file for product=network, facility=TNS

任何人都可以帮我解决这个问题。

谢谢大家。

1 个答案:

答案 0 :(得分:1)

首先尝试从命令行进行测试。关键是您运行lsnrctl而没有必需的环境变量ORACLE_HOME

在这里你重现了:

jxa@ub16a|2001$ ssh test1 /opt/oracle/product/11.2.0/dbhome_1/bin/lsnrctl status
Message 1053 not found; No message file for product=network,
facility=TNSMessage 1020 not found; No message file for product=network,
facility=TNSMessage 1021 not found; No message file for product=network,
facility=TNSMessage 1022 not found;
[...]

正确设置后ORACLE_HOME(在命令前添加):

jxa@ub16a|2007$ ssh test1 ORACLE_HOME=/opt/oracle/product/11.2.0/dbhome_1 \
                     /opt/oracle/product/11.2.0/dbhome_1/bin/lsnrctl status

LSNRCTL for Linux: Version 11.2.0.3.0 - Production on 09-NOV-2017 12:35:56
Copyright (c) 1991, 2011, Oracle.  All rights reserved.
Connecting to (ADDRESS=(PROTOCOL=tcp)(HOST=)(PORT=1521))
STATUS of the LISTENER
------------------------
Alias                     LISTENER
Version                   TNSLSNR for Linux: Version 11.2.0.3.0 - Production
[...]

现在只想弄清楚在java中添加环境变量的方法,你就完成了。或者只是将它添加到目标主机的.bashrc(最可能的Linux位置)或其他适当的init文件。

顺便说一句,您lsnrctl举报的错误是:

xxx:~ $ oerr tns 1101
01101, 00000, "Could not find service name %s"
// *Cause:  The ervice name could not be resolved by name-lookup.
// *Action: Verify that the listener name or service name specified to
// LSNRCTL has the correct name and address defined in LISTENER.ORA or in
// TNSNAMES.ORA.
xxx:~ $ 

我希望它有所帮助。