Extract multiple values from a tnsping output

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Extract multiple values from a tnsping output
# 1  
Old 08-28-2013
Extract multiple values from a tnsping output

Hi all,

Can anyone help with the following request?

I need to extract HOST value, SERVICE_NAME and msec value from a tnsping output and append to a file. The tnsping output is typically as follows:

Used TNSNAMES adapter to resolve the alias
Attempting to contact (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = rac01-scan.gxsonline.net)(PORT = 1521)) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = plt11cr)))
OK (50 msec)

Any ideas on the best way to do that?

Thanks in advance.


Last edited by radoulov; 08-28-2013 at 12:01 PM..
# 2  
Old 08-28-2013
NOTE: This does not report failed connections, to be really useful it probably should...
tnsping $SID | perl -e '$h_sid="$1,$2" if /\(HOST\s=\s([^)]+)\).+\(SERVICE_NAME\s=\s([^)]+)/;print "$hsid,$1\n" if /\((\d+)\s*msec\);'

# 3  
Old 08-28-2013
Hi thanks!

I got the following error when trying the command:

$tnsping plt11cr | perl -e '$h_sid="$1,$2" if /\(HOST\s=\s([^)]+)\).+\(SERVICE_NAME\s=\s([^)]+)/;print "$hsid,$1\n" if /\((\d+)\s*msec\);'
Search pattern not terminated at -e line 1.

can you clarify the $h_sid and $hsid values?

Should they be hardcoded?
# 4  
Old 08-29-2013
tnsping $SID | perl -ne '$h_sid="$1,$2" if /\(HOST\s=\s([^)]+)\).+\(SERVICE_NAME\s=\s([^)]+)/;print "$h_sid,$1\n" if /\((\d+)\s*msec\)/;' -


h_sid is the combination of the host and service id from the main line of the tnsping output, it is held over to be printed with the ping response time
# 5  
Old 08-29-2013
Thanks so much for tha. Works a treat.

Can you suggest how to concat DATE onto the end of the returned string?

Something like:
tnsping $SID | perl -ne '$h_sid="$1,$2" if /\(HOST\s=\s([^)]+)\).+\(SERVICE_NAME\s=\s([^)]+)/;print "$h_sid,$1\n" if /\((\d+)\s*msec\)/;' | `date`

Thanks again.


Last edited by jonnyd; 08-29-2013 at 04:27 PM.. Reason: Please use code tags
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Extract multiple values into corresponding variables

Here is my input # MANIFEST.MF Manifest-Version: 1.0 Build-Jdk: 1.6.0 Built-By: CM_TEAM Build_SvnRev: 662789 Build_Number: Build_Date: Wed 04/05/2017-20:48:19.17 Archiver-Version: Plexus Archiver Created-By: Apache Maven 3.1.0 Here is the expected output:... (4 Replies)
Discussion started by: kchinnam
4 Replies

2. Shell Programming and Scripting

awk to extract multiple values from file and add two additional fields

In the attached file I am trying to use awk to extract multiple values and create the tab-delimited desired output. In the output R_Index is a the sequential # and Pre_Enrichment is defaulted to .. I can extract from the values to the side of the keywords, but most are above and I can not... (2 Replies)
Discussion started by: cmccabe
2 Replies

3. UNIX for Dummies Questions & Answers

Read in Multiple log files and output selected variables and values to cvs file

I have several problems with my problems: I hope you can help me. 1) the If else statement I am getting an error message. My syntax must be incorrect because the entire statement is throwing an error. For example in filew.log if these items don't exist Memsize, SASFoundation and also if... (0 Replies)
Discussion started by: dellanicholson
0 Replies

4. UNIX for Dummies Questions & Answers

How to get/print host string only from tnsping output?

Hello All, I am using Linux OS. My idea is get the host name when we do tnsping in oracle. output of : tnsping DOELO01 TNS Ping Utility for Linux: Version - Production on 15-OCT-2015 20:20:05 Copyright (c) 1997, 2011, Oracle. All rights reserved. Used parameter files:... (2 Replies)
Discussion started by: Ariean
2 Replies

5. Shell Programming and Scripting

Read record from the text file contain multiple separated values & assign those values to variables

I have a file containing multiple values, some of them are pipe separated which are to be read as separate values and some of them are single value all are these need to store in variables. I need to read this file which is an input to my script Config.txt file name, first path, second... (7 Replies)
Discussion started by: ketanraut
7 Replies

6. Shell Programming and Scripting

Help/advice parsing Oracle tnsping output

Hi, tnsping is an Oracle tool that is sort of like a ping command. Unfortunately it does not come with a tool that can be used to parse its output which is very frustrating. Example output of tnsping are as below: $: tnsping testp1 TNS Ping Utility for Solaris: Version -... (3 Replies)
Discussion started by: newbie_01
3 Replies

7. Shell Programming and Scripting

Is it possible to extract these values from the output

Hi, I would like to search based of "java" and "-Dplatform.home=" and store these two values in bash variables. ps -xef | grep <pid> wlsuser 15160 15144 0 Feb 20 ? 17:27 /app1/jdk150_07/bin/IA64N/java -server -Xms1536m -Dplatform.home=/app1/bea/weblogic92... (13 Replies)
Discussion started by: mohtashims
13 Replies

8. Shell Programming and Scripting

Output breaking when returning multiple values

I've been trying to write a command-line function to grab a website's MX records and their ip addresses. The code below works with domains that only have one MX record: function kmx { mx=`host -t MX $1 | awk '{ print $7 }'`; ip=`host $mx | sed '/IPv6/d;/handled/d' | awk '{ print $4 }'`; ... (8 Replies)
Discussion started by: Azrael
8 Replies

9. UNIX for Dummies Questions & Answers

Using AWK: Extract data from multiple files and output to multiple new files

Hi, I'd like to process multiple files. For example: file1.txt file2.txt file3.txt Each file contains several lines of data. I want to extract a piece of data and output it to a new file. file1.txt ----> newfile1.txt file2.txt ----> newfile2.txt file3.txt ----> newfile3.txt Here is... (3 Replies)
Discussion started by: Liverpaul09
3 Replies

10. Shell Programming and Scripting

tnsping is not working

How to enable this command ? Thanks. ---------- Post updated at 03:36 AM ---------- Previous update was at 03:34 AM ---------- I forgot to tell it is Unix server (3 Replies)
Discussion started by: ajincoep
3 Replies
Login or Register to Ask a Question