RE: TNSPING for the instant client

From: Jeff Smith <>
Date: Fri, 15 May 2015 05:57:08 -0700 (PDT)
Message-ID: <70d1bed8-335b-4112-8059-d63c94be97fb_at_default>

For what it’s worth, we’ve added a TNSPING command to SQLcl, which is still in Early Adopter mode.


From: Mark W. Farnham [] Sent: Friday, May 15, 2015 6:31 AM
Cc: Oracle L
Subject: RE: TNSPING for the instant client


Interesting idea to use sqlplus with flags when there is no tnsping to be found.


From: HYPERLINK "" [] On Behalf Of Niall Litchfield Sent: Friday, May 15, 2015 6:20 AM
Cc: Oracle L
Subject: Re: TNSPING for the instant client


I rather think I prefer Laurent's approach I don't agree that tnsping is the equivalent of seeing if a given port on a given hostname/dns alias is accessible. 


The line 

·  Parses the TNS entry and extracts the host and port information

Rather assumes a tnsnames.ora file it seems to me, at the very least an indistinguishable tool would need to deal with ldap names etc. 


On Thu, May 14, 2015 at 6:39 AM, Mladen Gogala <HYPERLINK "" \> wrote:

Instant client is an excellent thing. It not only enables me to link PHP oci8 interface and Perl DBD::Oracle, it gives me the full-fledged sqlplus. There is only one utility that I am sorely missing: tnsping. I know that everybody knows that, but here is what tnsping does:

Parses the TNS entry and extracts the host and port information Contacts the host on the specified port and checks whether there is a listener listening on that port.

Sometimes, installing the full client is not an option, like on my Ubuntu box:

mgogala_at_umajor:~$ cat /etc/lsb-release

For some reason, Oracle Corp. doesn't support Ubuntu for the full client, so its installation is not an option. I really like tnsping, so here is what I came up with:

export PORT=1521
if [ -z "$1" ]; then

    echo "USAGE:tnsping hostname <port>"
    echo "      Port defaults to 1521";
    exit 1;

[ ! -z "$2" ] && export PORT=$2;
nc -v -z -w 3 $1 $PORT

This is not a complete equivalent of the original "tnsping" utility, because it doesn't parse the name and tell me where the sqlnet.ora is, but it does ask the desired host whether there is a listener on the desired port. The result looks like this:

mgogala_at_umajor:~$ tnsping oradb
Connection to oradb 1521 port [tcp/*] succeeded! mgogala_at_umajor:~$ tnsping oradb 1526
nc: connect to oradb port 1526 (tcp) failed: Connection refused mgogala_at_umajor:~$ tnsping oradb 22
Connection to oradb 22 port [tcp/ssh] succeeded!

I will probably modify the script and check whether TNS_ADMIN is defined and whether $TNS_ADMIN/sqlnet.ora exists, but so far, this script does what I wrote it for: it checks whether there is a listener on the host. Note that it even did "tnsping" on the port 22 (ssh), which is not possible with the original tnsping. So, for all instant client users and other Oracle enthusiasts, you are hereby granted the right to use and modify this script according to your needs, without any restrictions. Also, there is no warranty of any kind, either explicit or implied. The script depends on the "netcat" or "nc" command which does all of the dirty work. This short script is just a wrapper and I hope that some among you may find it useful. I will probably rewrite it in Perl and parse the TNS entry, but that's far too much work for this late hour. There is Net::Netcat module on CPAN, which makes it possible to write an even better emulation which will be literally indistinguishable from the original. Enjoy.


Mladen Gogala
Oracle DBA



Niall Litchfield
Oracle DBA

Received on Fri May 15 2015 - 14:57:08 CEST

Original text of this message