shell script- oracle connection problem


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting shell script- oracle connection problem
# 1  
Old 08-13-2002
Data shell script- oracle connection problem

Hi all,

I am having problem with a shell script. I have a couple of csv files. The shell script will do some operation on them, create a sql file which will then be called by sqlplus. The problem is to gracefully exit sqlplus at the end of every operation as I do not want to hang on to the connection. But I am getting an error the way I am doing it (see code). Can someone pl. help?


#!/bin/ksh

if [ -e *.csv ]
then

for csvfile in *.csv
do
echo "set feedback off" > temp.sql
echo "set echo off" >> temp.sql
echo "delete from test_table;" >> temp.sql
awk -F, -f parse.awk $csvfile >> temp.sql
echo "commit;" >> temp.sql
rm -f $csvfile

sqlplus -S uanme/pwd@mydb @temp.sql > test.log <<
endsqlplus
done

endsqlplus
exit 0

fi
# 2  
Old 08-13-2002
i think you could append exit at the end of the .sql file

and then just execute the .sql file by using:

sqlplus -S uanme/pwd@mydb @temp.sql > test.log
in your loop, you would probably want to rename your log file by concatenating the csvfile to it, just an idea hop it helps



i.e.

#!/bin/ksh

if [ -e *.csv ]
then

for csvfile in *.csv
do
echo "set feedback off" > temp.sql
echo "set echo off" >> temp.sql
echo "delete from test_table;" >> temp.sql
awk -F, -f parse.awk $csvfile >> temp.sql
echo "commit;" >> temp.sql
echo "exit;" >> temp.sql
rm -f $csvfile

sqlplus -S uanme/pwd@mydb @temp.sql > test.$csvfile.log
done

exit 0

fi
# 3  
Old 08-13-2002
That's right...you append it within the sql fiel and you'll be fine. I've used approach this before.
# 4  
Old 08-13-2002
Try this.

#!/bin/ksh

if [ -e *.csv ]
then

for csvfile in *.csv
do
echo "set feedback off" > temp.sql
echo "set echo off" >> temp.sql
echo "delete from test_table;" >> temp.sql
awk -F, -f parse.awk $csvfile >> temp.sql
echo "commit;" >> temp.sql
echo "exit;" >> temp.sql
rm -f $csvfile

sqlplus -S uanme/pwd@mydb <<EOF
@temp.sql
exit 0
EOF
done
fi

Good Luck!
Smilie
# 5  
Old 08-14-2002
Thanx for all the suggestions. The exit thing works perfectly fine.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shell script verify connection to Oracle if not successful

i have a script that connects to the oracle database and executes the query statements. it works fine and i would like to add some message to check if the connection to oracle is not successful. basically this is the code snippet: #!/bin/sh ... ... ... sqlplus -s username/password@dbName... (2 Replies)
Discussion started by: wtolentino
2 Replies

2. UNIX for Dummies Questions & Answers

How to fix connection to Oracle database through shell script?

I have a question regarding how to connect to Oracle Database through shell script. 1. If I want call a stored procedure on Linux server as this, it works. $sqlplus /nolog SQL*Plus: Release 12.1.0.2.0 Production on Fri Jun 12 14:49:49 2015 Copyright (c) 1982, 2014, Oracle. All rights... (2 Replies)
Discussion started by: duke0001
2 Replies

3. Shell Programming and Scripting

How to setup Oracle connection inside shell script?

Hi, We have Oracle Connection parameters set up in file name "TESTDB" at location /abc/etc.When I try to run my shell script it does not connect to Oracle database. Please let me know how "TESTDB" file can be called inside script. ####################### Setting the directories... (2 Replies)
Discussion started by: sandy162
2 Replies

4. Shell Programming and Scripting

How the user will provide the parameters for Oracle db connection in a shell script?

I'm new into unix. My question: is possible to write a shell script which will ask for the ORACLE_HOME, ORACLE_SID, USERNAME, PASSWORD to connect to Oracle db. In generally we have to set the ORACLE_HOME in .profile file. And after putting the 'sqlplus' command it asks for the username &... (6 Replies)
Discussion started by: priya001
6 Replies

5. Shell Programming and Scripting

Verifying oracle connection from shell script

Hi, Oracle 9.2 Solaris 10 From the shell script ........How can we verify whether oracle connection is successful or not ? Shell script will prompt the user to enter the oracle schema username, password and tns name. So, *how to verify whether oracle connection has been established or... (14 Replies)
Discussion started by: milink
14 Replies

6. Solaris

Solaris 10 ftp connection problem (connection refused, connection timed out)

Hi everyone, I am hoping anyone of you could help me in this weird problem we have in 1 of our Solaris 10 servers. Lately, we have been having some ftp problems in this server. Though it can ping any server within the network, it seems that it can only ftp to a select few. For most servers, the... (4 Replies)
Discussion started by: labdakos
4 Replies

7. Shell Programming and Scripting

oracle connection from shell script

Hi, For connecting to oracle my script is using the command sqlplus username/password@db_instance_name.For this to work i am setting ORACLE_HOME,TNS_ADMIN and ORACLE_SID in a seperate script.My question is,could we make a connection to oracle just by the command sqlplus... (4 Replies)
Discussion started by: DILEEP410
4 Replies

8. UNIX for Dummies Questions & Answers

sybase connection through shell-script

:mad: how do i connect to sybase through shell script written in linux (9 Replies)
Discussion started by: Amitabh
9 Replies

9. Shell Programming and Scripting

Connection to database through shell script

Hi when i am calling the shell script with two parameter like id and date it works fine.But the same shell script is call by java application it gives the error as shown below Thu Jan 8 04:13:22 EST 2009|The Get Segment Process Failed: SP2-0306: Invalid option. Usage: CONN where <logon>... (1 Reply)
Discussion started by: ravi214u
1 Replies

10. Shell Programming and Scripting

problem running shell script (for oracle export) in crontab

Hello Gurus, I've been tasked with solving a problem at my new job and I'm stumped. We've got a script that dynamically builds an oracle export parameter files and then runs export from the shell. it runs fine when using the shell, but will NOT run (fails in one spot everytime) when entered... (1 Reply)
Discussion started by: jsheehan223
1 Replies
Login or Register to Ask a Question