> We are using ldap naming (oracle internet directory for name resolution). Is there a command > to dump the whole ldap into a tnsnames.ora? (we need to generate this file automatically with > a batch) The following script generates TNS entries each on one single line. Interestingly, an entire TNS entry on one line still works. If you prefer to make the entries look nicer, some indentations may be necessary (see item 2 of http://yong321.freeshell.org/computer/OracleIdiosyncrasies.html). #!/usr/bin/perl -w #ldap2tnsnames.pl: Dump LDAP database connection strings into a one-entry-per-line format tnsnames.ora #Usage: ldap2tnsnames.pl > ldap2tnsnames.log #Change these parameters $host = "YourOIDHost"; #IP is fine $port = 389; #Normally no need to provide login credential; if prompted for it, you need to enable anonymous login #$user = "cn=orcladmin"; #Doesn't need to be super user #$password = "sesame"; $basedn = "cn=OracleContext,dc=acme,dc=com"; #Could be just "cn=OracleContext". Check with Directory Manager or any ldap browser first. #No need to change below for normal use. use POSIX qw/tmpnam/; $tmpfile = tmpnam; #Make sure the enclosed ldapsearch command works on cmdline first #qx(ldapsearch -h $host -p $port -D "$user" -w $password -b "$basedn" -s one "cn=*" orclnetdescstring > $tmpfile); qx(ldapsearch -h $host -p $port -b "$basedn" -s one "cn=*" orclnetdescstring > $tmpfile); open TMPFILE, "$tmpfile" or die "Can't open $tmpfile for read: $!\n"; $save = "\n"; while ($line=) { if ($line !~ /^$/ and $save !~ /^$/) { #print $save . $line; $save =~ /^cn=([\w\d]+)/; print "$1 = "; $line =~ /^orclnetdescstring=(.*)/; print "$1\n"; } $save = $line; } close TMPFILE; If you have defined aliases in LDAP, use this script dump aliases only: #!/usr/bin/perl -w #ldapalias2tnsnames.pl: dumps LDAP (OID) aliases to a tnsnames-format file #This script relies on an existing log file (ldap2tnsnames.log, which is tnsnames.ora in the #one-line-per-entry format) that contains connect identifiers these aliases point to. #Usage: ldapalias2tnsnames.pl > ldap_aliases.log #You can merge the two logs: #cat ldap2tnsnames.log ldap_aliases.log > $$; mv $$ ldap2tnsnames.log; #optionally: rm ldap_aliases.log $host = "YourOIDHost"; #IP is fine $port = 389; $basedn = "cn=OracleContext,dc=acme,dc=com"; #check first to make sure this works $ldap2tnsnameslog = "ldap2tnsnames.log"; #or whatever name you gave when you ran ldap2tnsnames.pl #No need to change below for normal use. use POSIX qw/tmpnam/; $tmpfile = tmpnam; #Please check ldapsearch on cmdline first to make sure it works qx(ldapsearch -h $host -p $port -b "$basedn" -s one "objectclass=orclNetServiceAlias" aliasedobjectname > $tmpfile); open LDAP2TNSNAMESLOG, "$ldap2tnsnameslog" or die "Can't open previously saved $ldap2tnsnameslog for read: $!\n"; open TMPFILE, "$tmpfile" or die "Can't open $tmpfile for read: $!\n"; $save = "\n"; while ($line=) { if ($line !~ /^$/ and $save !~ /^$/) { #print $save . $line; $save =~ /^cn=([\w\d]+)/; $alias=$1; print "#$alias = "; $line =~ /^aliasedobjectname=cn=([\w\d]+)/; $conn_id=$1; print "$conn_id\n"; seek LDAP2TNSNAMESLOG, 0, 0; while () { print "$alias = $1\n" if (/^$conn_id = (.*)/); } } $save = $line; } close TMPFILE; close LDAP2TNSNAMESLOG; **************** Outdated **************** Here's a quick and dirty way to generate the tnsnames.ora file. I connect to OID using Softerra Ldap Browser (http://www.softerra.com/products/ldapbrowser.php). Navigate to cn=OracleContext,(dc=youroptionalsubdomain,)dc=yourdomain,dc=com(or edu,gov,etc) Go to Edit or right click the OracleContext node and select LDIF Export to export to a file named OracleContext.ldif. You can choose One Level Only. You can also use one single ldapsearch command to generate this file. Make sure you limit the attribute to orclnetdescstring. Assume your database connection strings are always the same as their service names (if service_name is used): C:\>perl -nle "print \"$2 = $1\" if(/^orclnetdescstring: (.*service_name\s*=\s*([^.)]+).*)/i)" OracleContext.ldif > tnsnames.ora And assume some of your database connection strings are the same as SID names: C:\>perl -nle "print \"$2 = $1\" if(/^orclnetdescstring: (.*SID\s*=\s*([^.)]+).*)/i)" OracleContext.ldif >> tnsnames.ora If you don't have Perl, just put OracleContext.ldif on a UNIX box and run Perl there: perl -nle 'print "$2 = $1" if(/^orclnetdescstring: (.*service_name\s*=\s*([^.)]+).*)/i)' OracleContext.ldif > tnsnames.ora perl -nle 'print "$2 = $1" if(/^orclnetdescstring: (.*SID\s*=\s*([^.)]+).*)/i)' OracleContext.ldif >> tnsnames.ora **************** Not verified ******************** Alternatively, OID has a names server proxy. I think it means you can quickly set up a names server out of your OID installation. If so, launch namesctl and type dump_tnsnames at NAMESCTL> prompt. It would be nice if we could have a dump_tnsnames command running against OID without a names server. Yong Huang