RE: TNSPING for the instant client

From: Mark W. Farnham <mwf_at_rsiz.com>
Date: Fri, 15 May 2015 06:31:15 -0400
Message-ID: <00aa01d08efa$468bf550$d3a3dff0$_at_rsiz.com>



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

From: oracle-l-bounce_at_freelists.org [mailto:oracle-l-bounce_at_freelists.org] 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 <dmarc-noreply_at_freelists.org> 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
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_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
http://mgogala.freehostia.com





 

-- 

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



--
http://www.freelists.org/webpage/oracle-l
Received on Fri May 15 2015 - 12:31:15 CEST

Original text of this message