If you ever need to dump the contents of an Oracle OID (LDAP) server to a tnsnames.ora file, there’s an easy method using an awk script I wrote. The interesting thing about this script is that the output will be neatly formatted automatically.
The awk script consists of this:
**** Cut here ****
BEGIN {PAD=" ";CNT=0;FS="="}
{OUT=""; PC=1;CNT+=1}
{
if (CNT == 1)
{
O=$2
sub(",cn","",O)
print O " = "
}
else if (CNT == 2)
{
sub("^orclnetdescstring=","",$0)
{for (i=1;i<=length;i++)
{
CHR=substr($0,i,1)
if (CHR == "(")
{
PC+=1
WRK=OUT
sub(/ */,"",WRK)
if (WRK != "")
printf OUT "\n"
OUT=""
for (p=1;p<PC;p++)
OUT=PAD OUT
OUT=OUT CHR
}
else if (CHR == ")")
{
OUT=OUT CHR
printf OUT "\n"
PC-=1
OUT=""
for (p=1;p<PC;p++)
OUT=OUT PAD
}
else
OUT=OUT CHR
}
}
}
else if (CNT == 3)
CNT=0
}
**** Cut here ****
To use this awk script, paste everything in between the ‘**** Cut here ****’ lines into a file and name it whatever you like, for example ‘oid2tns.awk’. Once we have the script, we need to query the OID server and pass along the output. This will require a server that has OID installed; in our case we use the OID built into OAS. If you have your infrastructure and MT built on the same box, make sure you set the environment for infrastructure.
Here’s the syntax to combine the OID query and the awk script:
$ORACLE_HOME/bin/ldapsearch -h [SubYourOID] -b '' -s sub '(objectclass=orclNetService)' orclNetDescString | awk -f oid2tns.awk