LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 07-05-2011, 05:47 PM   #1
lyschange
LQ Newbie
 
Registered: May 2010
Posts: 8
Blog Entries: 2

Rep: Reputation: 0
sqlplus lgin script


i have the following script which when run from the linux sercer does not give me the sqlplus prompt...it does the su and leaves it there insted of continuing. Please assist. The target is to run the script and it shd su and login to sqlplus


<#!/bin/sh

su -l oracle
export ORACLE_SID=MYDB
sqlplus user/password

#>
~
 
Old 07-05-2011, 06:45 PM   #2
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 17,916

Rep: Reputation: 3689Reputation: 3689Reputation: 3689Reputation: 3689Reputation: 3689Reputation: 3689Reputation: 3689Reputation: 3689Reputation: 3689Reputation: 3689Reputation: 3689
Quote:
Originally Posted by lyschange View Post
i have the following script which when run from the linux sercer does not give me the sqlplus prompt...it does the su and leaves it there insted of continuing. Please assist. The target is to run the script and it shd su and login to sqlplus

<#!/bin/sh

su -l oracle
export ORACLE_SID=MYDB
sqlplus user/password

#>
~
Right. The "su" starts a new shell, and the commands past the "su" statement aren't getting passed, because the original shell you've started is 'on hold', until you exit the su shell, and go back. Try using sudo instead, as "sudo -u oracle sqlplus". If your environment variables are set for the oracle user anyway, you won't have to export it.
 
Old 07-05-2011, 07:00 PM   #3
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.8, Centos 5.10
Posts: 17,240

Rep: Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324
you could use the -c option http://linux.die.net/man/1/su
Code:
su - l oracle -c "export ORACLE_SID=MYDB && sqlplus user/password"
Personally, I'd expect the oracle acct to already have ORACLE_SID setup in the login. Also, if you're going to automate this, I'd put all the SQL into one file, so something like
Code:
su -l oracle -c "sqlplus user/password @mysqlfile.sql"
The only issue is security; do you really want user/passwd in a shell file?
 
1 members found this post helpful.
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Want to learn/use SQLPLUS in shell script saurabhmehan Linux - Newbie 1 09-15-2010 03:08 AM
sqlplus using shell script arfal Programming 3 02-08-2010 09:52 PM
How to enable auto-lgin fedora 11? linus72 Fedora 1 07-23-2009 10:17 AM
execute oracle procedure from linux script and sqlplus Stilltray Linux - Newbie 3 11-14-2008 11:35 AM
sqlplus command from script Grassie Coetzee LinuxQuestions.org Member Intro 2 03-13-2005 01:01 PM


All times are GMT -5. The time now is 03:25 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration