Sponsored Content
Top Forums Shell Programming and Scripting Sqlplus not connecting the 2nd time in for loop Post 303006499 by ajayakunuri on Thursday 2nd of November 2017 06:27:13 PM
Old 11-02-2017
Sqlplus not connecting the 2nd time in for loop

Hi,
I am trying to get the rows(First step is to get the poolid's and then second step run a loop to get the output based on each pool id and third connection is to get the member id and pool id based on a different condition) where based of certain conditions and storing it in a file. I wrote the below code, but when I try to execute it the first output is working fine and getting output.csv spooled, but from the next step I am getting login denied error message.

Code:
SP2-0306: Invalid option.
Usage: CONN[ECT] [{logon|/|proxy} [AS {SYSDBA|SYSOPER|SYSASM}] [edition=value]]
where <logon> ::= <username>[/<password>][@<connect_identifier>]
      <proxy> ::= <proxyuser>[<username>][/<password>][@<connect_identifier>]
SP2-0306: Invalid option.
Usage: CONN[ECT] [{logon|/|proxy} [AS {SYSDBA|SYSOPER|SYSASM}] [edition=value]]
where <logon> ::= <username>[/<password>][@<connect_identifier>]
      <proxy> ::= <proxyuser>[<username>][/<password>][@<connect_identifier>]
SP2-0157: unable to CONNECT to ORACLE after 3 attempts, exiting SQL*Plus

Also I keep seeing this on the screen:
Code:
cat: output1.csv: No such file or directory
cat: output1.csv: No such file or directory
cat: output1.csv: No such file or directory
cat: output1.csv: No such file or directory
cat: output1.csv: No such file or directory
cat: output1.csv: No such file or directory
cat: output1.csv: No such file or directory
cat: output1.csv: No such file or directory

Below is my code:

Code:
#!/bin/bash

umask 022

cd /data/datatransfer/Astra_pool_alert
rm /data/datatransfer/Astra_pool_alert/output.csv /data/datatransfer/Astra_pool_alert/output1.csv /data/datatransfer/Astra_pool_alert/final_output.csv /data/datatransfer/Astra_pool_alert/output3.csv 2>/dev/null
# Cleanup from previous run

# Connect to DB and spool query result into a CSV file
sqlplus -S 'ajay/ajay@(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=abdcef)(PORT=1521)))(CONNECT_DATA=(service_name=1234)))'  >>log_file_2>>err_file  <<EOF
set echo off head off feed off pagesize 0 trimspool on linesize 1000 colsep ,
spool output.csv REPLACE
select poolid from pools where poolname ='ajay';
spool off;
exit;
EOF

# Using while loop read values into variables from CSV file and create flat file for each records
for i in `cat /data/datatransfer/Astra_pool_alert/output.csv`
do
sqlplus -S 'ajay/ajay@(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=abdcef)(PORT=1521)))(CONNECT_DATA=(service_name=1234)))'  >>log_file_2>>err_file  <<EOF
set echo off head off feed off pagesize 0 trimspool on linesize 1000 colsep ,
spool output1.csv REPLACE
SELECT p.poolid||','||p.POOLNAME||','|| p.STARTDATE||','|| p.ENDDATE||','|| p.POOLTYPE||','|| p.RELEASENUMBER||','|| p.UPDATE_DATE||','|| pi.MEMBERID FROM
POOLS p inner join POOLSITEMS pi on p.POOLID=pi.POOLID
inner join mediagroups m on m.MEDIAGROUPID=pi.MEMBERID
WHERE p.poolid=$i and p.poolname ='ajay'
AND p.SITECHANNEL = 'ABC'
and p.enddate >= sysdate ORDER BY p.UPDATE_DATE DESC;
spool off;
exit;
EOF
	for j in `cat output1.csv`
	do
		awk -F "," '{print $1 "," $6}' $j > output2.csv
		while IFS=, read V1 V2
		do
sqlplus -S 'ajay/ajay@(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=abdcef)(PORT=1521)))(CONNECT_DATA=(service_name=1234)))'  >>log_file_2>>err_file  <<EOF
set echo off head off feed off pagesize 0 trimspool on linesize 1000 colsep ,
SPOOL output3.csv REPLACE
SELECT pi.memberid||,||pi.poolid||,||m.mediagtype from poolsitems pi inner join mediagroups m on
m.mediagroupid=pi.memberid where pi.poolid='$V1' and pi.RELEASENUMBER='$V2'
and m.mediagtype='1' and m.startdate <= sysdate and m.enddate >= sysdate;
spool off;
exit;
EOF
			echo "$j" >> /data/datatransfer/Astra_pool_alert/final_output.csv
		done < output2.csv

		break;
	done
done

I am not sure on why it is giving login denied as its the same id and password as first step. Please let me know if I am not doing it correctly.

Thanks
Ajay
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

error connecting to sqlplus

Hi, I wrote a shell script to call oracle procedure. But when i am trying to connet sqlplus with the fallowing statement It is giving me error " callproce.sh : sqlplus: not found". What could be the problem. sqlplus -s $CONNECT_STRING >$LOGFILE <<!! thank u all papachi (2 Replies)
Discussion started by: papachi
2 Replies

2. Shell Programming and Scripting

calling sqlplus from within a for loop

i'm not new to programming, but i AM new to unix scripting. here's my deal. this works: #!/bin/ksh echo "HELLO" /oracle_home/bin/sqlplus username/password@MYDB<<EOF SELECT COUNT(*) FROM EMPLOYEES; EOF exit echo "GOODBYE" this doesn't: #!/bin/ksh echo "HELLO" for x in 1 2... (4 Replies)
Discussion started by: akosz
4 Replies

3. Shell Programming and Scripting

Showing errors when connecting to sqlplus in shell script

hi, I am trying to automate the compilation of procedures stored in .sql files in Unix. Is there any way in which we can sho err if there errors are raised in the compilation? I am using the following code to connect to the sqlplus sqlplus ${SQL_USER}/${SQL_PASSWORD} (5 Replies)
Discussion started by: silas.john
5 Replies

4. Shell Programming and Scripting

connecting through sqlplus

I am trying to connect to one of the oracle sever using uni through sqlplus command: sqlplus -s BOXI_ALPH_AUDITOR,Q078_audit$@Q047 But its not getting connected. I tried using some different server using same syntax its working. What differene i found is the password is having no special... (2 Replies)
Discussion started by: gander_ss
2 Replies

5. UNIX for Dummies Questions & Answers

Connecting to Oracle DB using sqlplus

Hi, I am very new to shell scripting and trying to write a simple shell script in which i am trying to achieve the following: 1. Connect to oracle database hosted on a different server 2. fire a query on the oracle db 3. store the output in a variable 4. use this variable for further logic... (1 Reply)
Discussion started by: shrutihardas
1 Replies

6. Shell Programming and Scripting

Connecting to Oracle DB using sqlplus

Hi, I am very new to shell scripting and trying to write a simple shell script in which i am trying to achieve the following: 1. Connect to oracle database hosted on a different server 2. fire a query on the oracle db 3. store the output in a variable 4. use this variable for further logic... (26 Replies)
Discussion started by: shrutihardas
26 Replies

7. UNIX for Advanced & Expert Users

Connecting once using sqlplus and doing multiple queries

Hello everyone, It's my first week using unix and shell scripting. I tried creating a script that has a function that execute SQL query. my script looks something like this: ---------------------------------------------------- #!/bin/sh tableName="myTable" secondTable="secondTable"... (2 Replies)
Discussion started by: edlin_r
2 Replies

8. Shell Programming and Scripting

IF loop in sqlplus

Hi all, I am trying to use if loop inside SQLPLUS....is it possible...bcoz i tried a whole day with all the possibilities....no use...pls help Here's the code: KRITI = $? sqlplus -s /NOLOG << EOF connect $USER/$PASS IF $KRITI = 0 THEN create table kriti_employees( emp_id ... (1 Reply)
Discussion started by: kritibalu
1 Replies

9. Red Hat

TNS Timeout Error when connecting to SQLPLUS through scripts only

Hi, I am facing a strange issue when connecting to SQLPLUS via a shell scripts. I am using Linux 2.6.18-274.18.1 and gbash shell. When I connect to SQLPLUS through scripts then it throws TNS Time Out error ""sometimes"" and connects successfully other times.This is only happening when... (9 Replies)
Discussion started by: aashish.sharma8
9 Replies

10. Shell Programming and Scripting

Connecting sqlplus from UNIX with multiple select statement

hi, i have a requirement where i need to connect sqlplus from unix and i am able to do so by following command: cust_count=`sqlplus -s $ORACLE_USER/$ORACLE_PASS@$ORACLE_SID << EOF set pagesize 0 set feedback off set verify off ... (1 Reply)
Discussion started by: lovelysethii
1 Replies
All times are GMT -4. The time now is 05:27 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy