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


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers How to get/print host string only from tnsping output?
# 1  
Old 10-15-2015
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
Code:
TNS Ping Utility for Linux: Version 11.2.0.3.0 - Production on 15-OCT-2015 20:20:05

Copyright (c) 1997, 2011, Oracle.  All rights reserved.

Used parameter files:
/export/apps/oracli/dwh/admin/network/sqlnet.ora


Used TNSNAMES adapter to resolve the alias
Attempting to contact (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (COMMUNITY = TCPIP.world) (PROTOCOL = TCP) (Host = dlwh-db25) (Port = 1521))) (CONNECT_DATA = (SID = DOELO01) (GLOBAL_NAME = DOELO01.world)))
OK (50 msec)

Attempted code snippet:
awk '/Host/{match($0,/(Host =.*)/);print substr($0,RSTART+7,RLENGTH-88)}'

Is there any better way of achieving this as the value returned is not consistent as some of the hostnames are bigger and its printing additional characters. Basically from above (Host = dlwh-db25) I need to get content between "(" and after "=" and before ")" less spaces. Expected output for above would be dlwh-db25

Thank you.
# 2  
Old 10-16-2015
Try:
Code:
awk -F '[(] *Host *= *' 'NF>1{print substr($2, 1, match($2, / *[)]/) - 1)}'

This User Gave Thanks to Don Cragun For This Post:
# 3  
Old 10-16-2015
Your approach is not bad. Try to capture the first occurrence of the delimiter, not the last one:
Code:
awk '/Host/{match($0,/(Host =[^)]*)/);print substr($0,RSTART+7,RLENGTH-7)}' file

This User Gave Thanks to RudiC For This Post:
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Help on parsing Oracle RMAN output for string and print sections of a file

Hi, I need some advise on how to print 'sections' of the attached file. I am searching for some that says Marked Corrupt and print some lines after it. At the moment I am running the command below: sed -n -e '/Marked Corrupt/{N;N;p;}' rman_list_validate.txtThis gives me the following... (1 Reply)
Discussion started by: newbie_01
1 Replies

2. Solaris

Host name in front of pkginfo output

hello all I am trying to create a comma seperated file of the pkginfo command. The follwoing works pretty well. pkginfo -l | egrep '(BASEDIR|NAME|VERSION)' | awk '{print}' ORS=', ' however, there are two issues. 1, For some reason it does not load into excel properly. It loads as... (7 Replies)
Discussion started by: busi386
7 Replies

3. Solaris

Host name in front of ps output

hello All. I am working on something that should be really simply. It turns out that its not. I am trying to produce output to list the hostname along with all the current running programs. the script im using is: for PS in `ps -Ao "user,args" | cut -d' ' -f1,2` do echo "`uname -n`, $PS"... (5 Replies)
Discussion started by: busi386
5 Replies

4. 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 11.2.0.2.0 -... (3 Replies)
Discussion started by: newbie_01
3 Replies

5. Shell Programming and Scripting

Compare columns of multiple files and print those unique string from File1 in an output file.

Hi, I have multiple files that each contain one column of strings: File1: 123abc 456def 789ghi File2: 123abc 456def 891jkl File3: 234mno 123abc 456def In total I have 25 of these type of file. (5 Replies)
Discussion started by: owwow14
5 Replies

6. Shell Programming and Scripting

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 =... (4 Replies)
Discussion started by: jonnyd
4 Replies

7. Shell Programming and Scripting

Print all Host on local network

Hello guys, I would like to develop a script which takes a host name as argument and displays a message whether the host is on the local network or not. How can I accomplish that? Is there a file or command that I can use to list all host on the local network? :confused: (4 Replies)
Discussion started by: Learn4Life
4 Replies

8. Shell Programming and Scripting

Awk script to run a sql and print the output to an output file

Hi All, I have around 900 Select Sql's which I would like to run in an awk script and print the output of those sql's in an txt file. Can you anyone pls let me know how do I do it and execute the awk script? Thanks. (4 Replies)
Discussion started by: adept
4 Replies

9. 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

10. UNIX for Advanced & Expert Users

Unix: print on printer on another machine (host)

Hi all,sorry for my english but i don't speak it very well. I have a problem, i need to print a file from a unix machine to a printer on another unix machine (with another host). I think that it's possible making a connection with telnet to this machine and after to print on the machine in... (3 Replies)
Discussion started by: giugy
3 Replies
Login or Register to Ask a Question