LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   sqlplus lgin script (https://www.linuxquestions.org/questions/linux-newbie-8/sqlplus-lgin-script-890086/)

lyschange 07-05-2011 04:47 PM

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

#>
~

TB0ne 07-05-2011 05:45 PM

Quote:

Originally Posted by lyschange (Post 4406085)
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.

chrism01 07-05-2011 06:00 PM

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?


All times are GMT -5. The time now is 05:48 AM.