RE: TNSPING for the instant client

  • From: Jeff Smith <jeff.d.smith@xxxxxxxxxx>
  • To: mwf@xxxxxxxx, niall.litchfield@xxxxxxxxx
  • Date: Fri, 15 May 2015 05:57:08 -0700 (PDT)

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

 

From: Mark W. Farnham [mailto:mwf@xxxxxxxx]
Sent: Friday, May 15, 2015 6:31 AM
To: niall.litchfield@xxxxxxxxx
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
"mailto:oracle-l-bounce@xxxxxxxxxxxxx"oracle-l-bounce@xxxxxxxxxxxxx
[mailto:oracle-l-bounce@xxxxxxxxxxxxx] 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 
http://laurentschneider.com/wordpress/2012/11/tnsping-and-instant-client.html.
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
"mailto:dmarc-noreply@xxxxxxxxxxxxx"; \ndmarc-noreply@xxxxxxxxxxxxx> 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@umajor:~$ cat /etc/lsb-release
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=15.04
DISTRIB_CODENAME=vivid
DISTRIB_DESCRIPTION="Ubuntu 15.04"

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:

#!/bin/sh
export PORT=1521
if [ -z "$1" ]; then
    echo "USAGE:tnsping hostname <port>"
    echo "      Port defaults to 1521";
    exit 1;
fi;
[ ! -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@umajor:~$ tnsping oradb
Connection to oradb 1521 port [tcp/*] succeeded!
mgogala@umajor:~$ tnsping oradb 1526
nc: connect to oradb port 1526 (tcp) failed: Connection refused
mgogala@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
http://mgogala.freehostia.com





 

--

Niall Litchfield
Oracle DBA
http://www.orawin.info

Other related posts: