LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   tnsping: command not found (https://www.linuxquestions.org/questions/linux-software-2/tnsping-command-not-found-818856/)

thomas2004ch 07-09-2010 03:37 AM

tnsping: command not found
 
I want to test the listener of a database. But as I type the tnsping, it fails and show the error as follow:
Code:

-bash: tnsping: command not found
Should I install the tnsping? How?

paulsm4 07-09-2010 04:45 AM

"tnsping" is an Oracle command.

You need Oracle installed on your system, and you need the Oracle programs in your search path.

To modify your $PATH, of course, you can edit your $HOME/.bashrc user environment initialization file.

'Hope that helps .. PSM

thomas2004ch 07-15-2010 04:52 AM

Quote:

Originally Posted by paulsm4 (Post 4028122)
"tnsping" is an Oracle command.

You need Oracle installed on your system, and you need the Oracle programs in your search path.

To modify your $PATH, of course, you can edit your $HOME/.bashrc user environment initialization file.

'Hope that helps .. PSM


I've installed the oracle 10 client. But couldn't find the tnsping. Seems from oralce 10 no tnsping anymore?

BirdRacer 07-15-2010 09:44 AM

Quote:

Originally Posted by thomas2004ch (Post 4033715)
I've installed the oracle 10 client. But couldn't find the tnsping. Seems from oralce 10 no tnsping anymore?

It should be in your $ORACLE_HOME/bin directory. Do this:

Code:

env | grep ORACLE_HOME
to show your $ORACLE_HOME environment variable, or just do:

Code:

cd $ORACLE_HOME/bin
to put you in that directory, then do an 'ls -l tnsping' to see the file. If that is correct, then do:

Code:

PATH=$PATH:$ORACLE_HOME/bin ; export PATH
to add it to your PATH variable. You would want to put this in your .bashrc or .bash_profile to make it permanent.

DanDMKE 01-14-2023 01:55 PM

tnsping implemented as ksh script
 
You probably have an Oracle Instant Client. That client install option does not come with the 'tnsping' command.
I think you can get 'sqlplus' command as an optional RPM package.

Anyhow, I wrote my own 'tnsping' using a Korn shell script, which relies upon 'sqlplus' command being installed and tnsnames.ora file.
Entries in tnsnames.ora are case-insensitive. We do a fake login (regit / tiger) with 'sqlplus' command and watch for the expected login error.
If we get the login error, we display 'OK' along with how many milliseconds it took to run the 'sqlplus' attempt.
If we get something else, we display that error (either ORA-xxxxx or TNS-xxxxx).

This is intended to be a quick and dirty solution to my immediate need, on RHEL 8.7
If you find it useful, GREAT!

Code:

#!/bin/ksh

if [[ "X$1" == "X" ]]
then
  echo "Usage: tnsping <DB_instance>"
  exit 1
fi

if [[ "X${TNS_ADMIN}" == "X" ]]
then
  echo "Oracle environment variable TNS_ADMIN is not set."
  echo 10
fi

if [[ "X${ORACLE_HOME}" == "X" ]]
then
  echo "Oracle environment variable ORACLE_HOME is not set."
  echo 20
fi

if [ ! -f ${TNS_ADMIN}/tnsnames.ora ]
then
  if [ -f ${ORACLE_HOME}/network/admin/tnsnames.ora ]
  then
      TNS_ADMIN=${ORACLE_HOME}/network/admin
  else
      echo "${TNS_ADMIN}/tnsnames.ora does not exist"
      exit 30
  fi
fi

chk=$(grep -ic $1 ${TNS_ADMIN}/tnsnames.ora)
if [ ${chk} -eq 0 ]
then
  echo "Entry $1 not found in tnsnames.ora"
  exit 40
else
  db_inst=$1
fi

tmp_file=/tmp/tnsping.$$

st_time=$(echo $SECONDS | sed 's#\.##')
${ORACLE_HOME}/bin/sqlplus -L -S regit/tiger@${db_inst} > ${tmp_file} 2>&1
en_time=$(echo $SECONDS | sed 's#\.##')

el_time=$(expr ${en_time} - ${st_time})

chk=$(grep -c 'ORA-01017: invalid username/password; logon denied' ${tmp_file})
if [ ${chk} -gt 0 ]
then
  echo "OK (${el_time} msec)"
else
  grep -E 'ORA-|TNS-' ${tmp_file}
fi

/bin/rm -f ${tmp_file}

exit 0



All times are GMT -5. The time now is 06:13 AM.