Sponsored Content
Top Forums Shell Programming and Scripting Need to capture the service name from tnsnames.ora and create connect string Post 302311663 by radoulov on Wednesday 29th of April 2009 09:27:30 AM
Old 04-29-2009
Assuming all services are defined using the format in the example above the code below will try to execute the script checkinstance.sql connecting to every service using sqlplus (assuming it can be found in the path):
Code:
perl -ne'
  /^(\w+)\s*=\s*$/ and 
    $stmt .= "conn username/pass\@$1\n\@checkinstance.sql\n";
  if (eof) {
    ($cmd = <<_END_) =~ s/^\s+//gm;
      sqlplus /nolog<<_SQL_
        $stmt
      _SQL_
_END_
    qx/$cmd/;
       }' tnsnames.ora

If you really only want to generate the statements:

Code:
perl -lne'
  /^(\w+)\s*=\s*$/ and 
    print "conn username/pass\@$1\n\@checkinstance.sql\ndisc"
  ' tnsnames.ora

 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

ORA-12154: TNS:could not resolve service name

Hi everyone, when i run ; sqlplus -s username/password@TTTEST @umt.sql i take "ORA-12154: TNS:could not resolve service name" i want to run "umt.sql" query and also see result. thanx for your helping. (6 Replies)
Discussion started by: temhem
6 Replies

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

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

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

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

Shell script to capture ORA errors from Alert Log

Hi, as the title says, I am after a simple script, which will open the Alert log from an 11.2.0.1 Linux environment and mail the error message and description to a recipient email address. I can then schedule this job via cron and let it run every 15 minutes. I have searched online... (16 Replies)
Discussion started by: jnrpeardba
16 Replies

7. Shell Programming and Scripting

Tnsnames.ora

Hi, I would like to modify, in script schell, the line right above (DESCRIPTION and check three cases : 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... (10 Replies)
Discussion started by: elcaro
10 Replies

8. Shell Programming and Scripting

Shell script to capture Current day ORA errors from Alert Log

Please provide Shell script to capture ORA errors from Alert Log for a given date or Current date. -Veera (1 Reply)
Discussion started by: Veera_V
1 Replies

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

10. 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
SQLSRV_SEND_STREAM_DATA(3)												SQLSRV_SEND_STREAM_DATA(3)

sqlsrv_send_stream_data - Sends data from parameter streams to the server

SYNOPSIS
bool sqlsrv_send_stream_data (resource $stmt) DESCRIPTION
Send data from parameter streams to the server. Up to 8 KB of data is sent with each call. PARAMETERS
o $stmt - A statement resource returned by sqlsrv_query(3) or sqlsrv_execute(3). RETURN VALUES
Returns TRUE if there is more data to send and FALSE if there is not. EXAMPLES
Example #1 sqlsrv_send_stream_data(3) example <?php $serverName = "serverNamesqlexpress"; $connectionInfo = array( "Database"=>"dbName", "UID"=>"username", "PWD"=>"password" ); $conn = sqlsrv_connect( $serverName, $connectionInfo); if( $conn === false ) { die( print_r( sqlsrv_errors(), true)); } $sql = "UPDATE Table_1 SET data = ( ?) WHERE id = 100"; // Open parameter data as a stream and put it in the $params array. $data = fopen( "data://text/plain,[ Lengthy content here. ]", "r"); $params = array( &$data); // Prepare the statement. Use the $options array to turn off the // default behavior, which is to send all stream data at the time of query // execution. $options = array("SendStreamParamsAtExec"=>0); $stmt = sqlsrv_prepare( $conn, $sql, $params, $options); sqlsrv_execute( $stmt); // Send up to 8K of parameter data to the server // with each call to sqlsrv_send_stream_data. $i = 1; while( sqlsrv_send_stream_data( $stmt)) { $i++; } echo "$i calls were made."; ?> SEE ALSO
sqlsrv_prepare(3), sqlsrv_query(3). PHP Documentation Group SQLSRV_SEND_STREAM_DATA(3)
All times are GMT -4. The time now is 05:40 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy