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