Logging into oracle or SQL from shell script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Logging into oracle or SQL from shell script
# 1  
Old 02-23-2007
Logging into oracle or SQL from shell script

Hi,

I have a shell script where I log on to sqlplus like this

log()
{
sqlplus -s scott/tiger <<!
select count(*) from EMP;
!
}

log

Here I have hardcoded/used the username : scott and password : tiger directly to log on to SQLPLUS. If i have my log in information in my profile file then how can I make use of it, instead of harcoding values in the script.

Thanks in advance
# 2  
Old 02-23-2007
Let usernm and pwd be variables defined in the .profile

sqlscpt.sh
Code:
log()
{
sqlplus -s $usernm/$pwd <<!
select count(*) from EMP;
!
}

log

Run the script like this
Code:
. ./sqlscpt.sh

# 3  
Old 04-10-2007
I have a little writeup on running SqlPlus commands and PL/SQL procedures from a shell script. Take a look at it. Its located at http://timarcher.com/?q=node/48

It demonstrates a simple way to do it under Oracle and RedHat Linux. Furthermore I show you how to get the return codes from the sql plus execution into your unix script so that you can jump to an appropriate path of execution in your shell script.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to pass Oracle sql script as argument to UNIX shell script?

Hi all, $ echo $SHELL /bin/bash Requirement - How to pass oracle sql script as argument to unix shell script? $ ./output.sh users.sql Below are the shell scripts and the oracle sql file in the same folder. Shell Script $ cat output.sh #!/bin/bash .... (7 Replies)
Discussion started by: a1_win
7 Replies

2. Shell Programming and Scripting

Shell script with Oracle PL/SQL

Hi Gurus, I am new to this unix world...I need your help to walk through. I want to learn shell scripting..... The shell script which can be able to use with oracle pl/sql... So please suggest me which shell is good. Which Unix/Linux version is good for this to Install to get practice the... (8 Replies)
Discussion started by: GaneshAnanth
8 Replies

3. UNIX for Advanced & Expert Users

Use of Oracle pl/sql in UNIX shell script

Hi, I have basic knowledge on how to write pl/sql code inside shell script. I am looking for more advance thing. Is there any book for that which can just talk about how to write more advance plsql code inside shell script. Please help Thanks!!!!!! (1 Reply)
Discussion started by: diehard
1 Replies

4. Programming

pass value from Oracle sql to Korn shell

Hi All , I am trying to pass a value from sqlplus to korn shell . There is a table tab1 in Oracle that has a column userdate. I need to pass the userdate to the korn shell . This is what I am doing . VALUE=`sqlplus -silent username/password << END set pagesize 0 feedback off verify off... (14 Replies)
Discussion started by: megha2525
14 Replies

5. Shell Programming and Scripting

How to run a SQL select query in Oracle database through shell script?

I need to run a SQL select query in Oracle database and have to capture the list of retrieved records in shell script. Also i would like to modify the query for certain condition and need to fetch it again. How can i do this? Is there a way to have a persistent connection to oracle database... (9 Replies)
Discussion started by: vel4ever
9 Replies

6. Shell Programming and Scripting

Running Oracle SQL from shell script

Hi, can anyone help me with this script please. I need the oracle command to go into the unix batch file. #!/bin/sh # A menu driven Shell script which has following options # for acmtoron@> # # # Exit # As per option do the job #---- while : do clear echo " A C M LOG MONITORING... (0 Replies)
Discussion started by: tinaaguilera
0 Replies

7. Shell Programming and Scripting

How to capture value in shell variable from oracle sql?

Hi Friends, Do someone know how to capture value in a shell variable from oracle sql? Requirement : In a table we want to count the number of records and want to pass this value to a shell variable where it can be manipulated later. In ksh shell we open oracle connection from sqlplus. For... (1 Reply)
Discussion started by: sourabhsharma
1 Replies

8. Shell Programming and Scripting

Calling SQL LDR and SQL plus scripts in a shell script

Hi- I am trying to achieve the following in a script so I can schedule it on a cron job. I am fairly new to the unix environment... I have written a shell script that reads a flat file and loads the data into an Oracle table (Table1) via SQLLDR. This Works fine. Then, I run a nested insert... (5 Replies)
Discussion started by: rajagavini
5 Replies

9. Shell Programming and Scripting

Shell script for accessing a file in the network drive and invoking oracle sql loader

Hi, Please let me know if anybody is having a solution handy for the below tasks... It would be helpful if somebody can resolve my query. I am new to unix and oracle environment and looking for some online reference for completing a task. Task: Check if the network drive exists Check... (0 Replies)
Discussion started by: sayydevara
0 Replies

10. UNIX for Dummies Questions & Answers

how to pass values from oracle sql plus to unix shell script

how to pass values from oracle sql plus to unix shell script (2 Replies)
Discussion started by: trichyselva
2 Replies
Login or Register to Ask a Question