Tnsnames.ora


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Tnsnames.ora
# 1  
Old 03-26-2014
Tnsnames.ora

Hi,

I would like to modify, in script schell, the line right above (DESCRIPTION and check three cases :

Code:
if line contain ".world" then line=line-".world" concat "," concat line
if line dont contain ".world" then line=line concat "," concat line concat".world"
else line=line

Keep in mind that there may or may not be spaces between the '(' and the word DESCRIPTION. So valid examples can be something like this:

Code:
PRI =
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST = 10.0.3.7)(PORT = 1521))
    )
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = pri)
      (INSTANCE_NAME = pri)
    )
  )

STDBY.world =
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST = 10.0.3.5)(PORT = 1521))
    )
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = stdby)
      (INSTANCE_NAME = stdby)
    )
  )


AIXSNAP.us.net =
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST = 10.9.0.5)(PORT = 1521))
    )
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = aixsnap)
      (INSTANCE_NAME = aixsnap)
    )
  )

only the lines PRI and STDBY.world can be modified as :
Code:
PRI,PRI.world=
and 
STDBY,STDBY.world=

Many thanks

Last edited by elcaro; 03-26-2014 at 09:15 PM..
# 2  
Old 03-27-2014
If we check for contains ".world" and doesn't contain ".world", where do we use else case?
# 3  
Old 03-27-2014
I mean we check if is string or string.world.
If it is many_strings , like aixsnap.us.net, then we consider it in others and don't modify.

Many thanks.
# 4  
Old 03-27-2014
From python shell:
Code:
>>> text = '''
... PRI =
...   (DESCRIPTION =
...     (ADDRESS_LIST =
...       (ADDRESS = (PROTOCOL = TCP)(HOST = 10.0.3.7)(PORT = 1521))
...     )
...     (CONNECT_DATA =
...       (SERVER = DEDICATED)
...       (SERVICE_NAME = pri)
...       (INSTANCE_NAME = pri)
...     )
...   )
... 
... STDBY.world =
...   (DESCRIPTION =
...     (ADDRESS_LIST =
...       (ADDRESS = (PROTOCOL = TCP)(HOST = 10.0.3.5)(PORT = 1521))
...     )
...     (CONNECT_DATA =
...       (SERVER = DEDICATED)
...       (SERVICE_NAME = stdby)
...       (INSTANCE_NAME = stdby)
...     )
...   )
... 
... 
... AIXSNAP.us.net =
...   (DESCRIPTION =
...     (ADDRESS_LIST =
...       (ADDRESS = (PROTOCOL = TCP)(HOST = 10.9.0.5)(PORT = 1521))
...     )
...     (CONNECT_DATA =
...       (SERVER = DEDICATED)
...       (SERVICE_NAME = aixsnap)
...       (INSTANCE_NAME = aixsnap)
...     )
...   )
... '''
>>> 
>>> print re.sub(re.compile(r'^\s*(\w+)(?:\.world|\s*)(?=\s*=\s*\n\s*[\(]\s*DESCRIPTION)',re.M),r'\1,\1.world',text)
PRI,PRI.world=
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST = 10.0.3.7)(PORT = 1521))
    )
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = pri)
      (INSTANCE_NAME = pri)
    )
  )
STDBY,STDBY.world =
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST = 10.0.3.5)(PORT = 1521))
    )
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = stdby)
      (INSTANCE_NAME = stdby)
    )
  )


AIXSNAP.us.net =
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST = 10.9.0.5)(PORT = 1521))
    )
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = aixsnap)
      (INSTANCE_NAME = aixsnap)
    )
  )

In a script:
Code:
# cat lsnr_sub.py 
#!/usr/bin/env python
import sys
import re

try:
   with open(sys.argv[1],'r') as f:
      text = f.read()
except:
   print "err with file"
   sys.exit(5)

reg_ex = (r'^\s*(\w+)(?:\.world|\s*)'
          r'(?=\s*=\s*\n\s*[\(]\s*DESCRIPTION)')
print re.sub(re.compile(reg_ex,re.M),r'\1,\1.world',text)

Usage:
Code:
# ./lsnr_sub.py listener.ora


Last edited by Klashxx; 03-27-2014 at 06:50 AM.. Reason: Script integration
# 5  
Old 03-27-2014
Thank you klashxx, is it possible to have it in ksh please ?

---------- Post updated at 11:45 AM ---------- Previous update was at 11:03 AM ----------

I receive a syntax error for line 6 : open...
Could you reply in ksh please ?

---------- Post updated 28-03-14 at 12:09 AM ---------- Previous update was 27-03-14 at 11:45 AM ----------

Hi,
i am not familiar with python, so when i run the command line :
Code:
>>> print re.sub(re.compile(r'^\s*(\w+)(?:\.world|\s*)(?=\s*=\s*\n\s*[\(]\s*DESCRIPTION)',re.M),r'\1,\1.world',text)
with adding ( import re)

it run very well, however when i run the script i receive the syntax error in line 6.
Thank you for reply.
# 6  
Old 03-27-2014
Here is an awk solution:

Code:
awk '
/\(DESCRIPTION/{
   if(index(prev,".world")) sub(/^[^.]+/,"&,&",prev)
   if(!index(prev,".")) sub(/^[^ ]+/,"&,&.world",prev)
}
NR>1 {print prev}
{prev=$0}
END {print prev}' infile

# 7  
Old 03-27-2014
Many thanks Chubler_XL,
so, how can i use it in a script please ?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Red Hat

Ora-27603:ora-27626:

Hi, User claim that job is running slow from their end. I DBA found in database the below errors in alert log file. ORA-27603: Cell storage I/O error, I/O failed on disk o/192.168.10.3/RECO_DM01_CD_01_drm01 at offset 13335789568 for data length 1048576 ORA-27626: Exadata error: 2201 (IO... (2 Replies)
Discussion started by: Maddy123
2 Replies

2. AIX

I cannot find dsn and TNSNAMES.ora on UNIX

Where can I find dsn and TNSNAMES.ora on UNIX AIX Thanks for contribution (3 Replies)
Discussion started by: digioleg54
3 Replies

3. Shell Programming and Scripting

Tnanames.ora parser

Dears How can I use shell to parser this file? PRI = (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = 10.0.3.7)(PORT = 1521)) (ADDRESS = (PROTOCOL = TCP)(HOST = 10.0.3.17)(PORT = 1521)) ) (CONNECT_DATA = (SERVER = DEDICATED) ... (6 Replies)
Discussion started by: eric0826
6 Replies

4. Shell Programming and Scripting

Removing section from tnsnames.ora

Hi, I am trying to write a script or command to remove a section from tnsnames.ora file in the following example I would like to remove tns_alias2 section $ cat tnsnames.ora tns_alias1 = (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = host1 )(PORT = 1521)) ... (3 Replies)
Discussion started by: ynixon
3 Replies

5. UNIX for Advanced & Expert Users

grep all ORA errors except one ORA error

Hi - I am trying to grep all "ORA" errors in a log files.I have to grep all ORA errors except one error for example ORA-01653.How can exclude that error in "grep" command? In following "grep" command I want to exclude "ORA-01653" error grep -i ORA alert.log >>/tmp/ora_errors.txt ... (7 Replies)
Discussion started by: Mansoor8810
7 Replies

6. Shell Programming and Scripting

sed: parsing tnsnames.ora

All: Can sombodoy help me out with a sed command? Assume I have the following: PRI = (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = 10.0.3.7)(PORT = 1521)) ) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = pri) ... (3 Replies)
Discussion started by: BeefStu
3 Replies

7. Solaris

maxuprc and maxusers - ORA-27300, ORA-27301, ORA-27302

Hi all, Am intermittently getting the following errors on one of my databases. Errors in file /oracle/HRD/saptrace/background/hrd_psp0_13943.trc: ORA-27300: OS system dependent operation:fork failed with status: 12 ORA-27301: OS failure message: Not enough space ORA-27302:... (1 Reply)
Discussion started by: newbie_01
1 Replies

8. UNIX for Dummies Questions & Answers

find tnsnames.ora in unix

Can we find out what is the location of tnsnames.ora file used by the hp unix. (3 Replies)
Discussion started by: Sudipshib
3 Replies

9. Solaris

init.ora

what is the function of the init.ora file and suppose by mistake it gets deleted , what will be the consequences on the server (1 Reply)
Discussion started by: asalman.qazi
1 Replies

10. Shell Programming and Scripting

Need to capture the service name from tnsnames.ora and create connect string

ghkjkjoj (4 Replies)
Discussion started by: chetankelvin
4 Replies
Login or Register to Ask a Question