Is there an API that will read a TNS file and present it in some easy-to-use data structure?
I would like to get a list of all my TNS entries. This works but is not particularly elegant!
grep '^[a-zA-Z].*=' /etc/tnsnames.ora | sed 's/[ =].*//'
另一个不是很简单的解决方案是 ANTLR。您可以使用 ANTLR 来解析tnsnames.ora
. 在ANTLR 语法列表页面上,您会找到可以解析的语法tnsnames.ora
,sqlnet.ora
以及listener.ora
我不确定 TNSPing 是否对您更有用。它将输出如下:
TNS Ping Utility for Linux: Version 10.2.0.1.0 - Production
on 01-MAR-2009 02:02:33
Copyright (c) 1997, 2005, Oracle. All rights reserved.
Used parameter files:
Used TNSNAMES adapter to resolve the alias
Attempting to contact (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)
(HOST = myhostname)(PORT = 1521)) (CONNECT_DATA = (SID = mydb)))
OK (80 msec)
问题是您必须将 TNS 名称传递给 ping,这在您的场景中可能会也可能不会。