to run sql as superuser


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting to run sql as superuser
# 1  
Old 04-28-2008
to run sql as superuser

hi All,

In my script I want to run some drop and select statements in the same host as a different user.I am inputting password for the superuser from the user who will be executing the script.

ie ,
Quote:
#!/bin/ksh
echo " \n\n\t Enter the superuser's password:\c"
read pass
I would be greatfull to you experts if you could suggest me how to proceed.
Sreejith_VK
# 2  
Old 04-28-2008
Imagine big bold letters here: Don't Do That.

Simply run su - user -c "commands" and su will take care of prompting for the password.

Reading the root password in a userspace script is not recommended.
# 3  
Old 04-28-2008
Hi ,

Thanks a lot for your reply.
Can you pls site an example also?
I tried reproducing the command but failed.
I was actually trying...

Code:
su - user1 -c "echo 'user123'"
sleep 10
sqlplus "/as systemdba"
select name from v$database; <<+ENDOFSQL+
exit
+ENDOFSQL+
exit

The prompt for password came and the sleep command or echo command is not executed after wards.
The password expected is not root password.
Sreejith_VK
# 4  
Old 04-28-2008
You said "superuser password", I assumed root password.

The idea would be 'su - user1 "commands to connect to sql"' -- if it's a long script then just put that in a file and execute that file.
# 5  
Old 04-28-2008
Like ...

su - user -c "myscript.sh"

And in myscript.sh you'd have something like (perhaps) ...

...
sqlplus /as sysdba @myscript.sql
...

And lastly, in myscript.sql you'd have (or similar) ...

select name from v$database ;

Anyways, hope that helps some Smilie

Cheers,
Cameron
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Script to run sql query.

Please read How To Ask Questions The Smart Way (1 Reply)
Discussion started by: balu_279013
1 Replies

2. Shell Programming and Scripting

Time taken to run a SQL script

Hello I am asked to run around 5-6 SQL queries in a shell script and take a note of the time taken to execute each query to a file. How do I get the time taken to run the individual SQL queries (2 Replies)
Discussion started by: vat1kor
2 Replies

3. Shell Programming and Scripting

Run SQL thru shell script: how to get a new line when run sql query?

Hi, this's Pom. I'm quite a new one for shell script but I have to do sql on shell script to query some information from database. I found a concern to get a new line...When I run my script, it retrieves all data as wondering but it's shown in one line :( What should I do? I'm not sure that... (2 Replies)
Discussion started by: Kapom
2 Replies

4. Shell Programming and Scripting

Run Sql plus in shell script

Hello, I want to connect to ssh, run a query, and store that into a variable in the shell script. Also I need to pass the variable back to php to display the query results. I have created a public/private key pair for ssh connection and that is working fine. Also I am able to run query in the... (8 Replies)
Discussion started by: shekhar2010us
8 Replies

5. Shell Programming and Scripting

Run SQL with parameters from a file

Hello, I need to run a SQL which will get parameters from a .txt file. Basically I need to run following query select * from a table where identity_id in <list of values in A.txt file> A.txt file is having values 1 2 3 4 5 I need the SQL to pick the values from the file and... (2 Replies)
Discussion started by: asdban
2 Replies

6. Shell Programming and Scripting

shell script to run .sql files

hi Friends, Please help me in writing shell script to run list of sql files. database is Oracle 9i, unix os is solaris Requirement is 1. sql file must take two inputs a)feed id and b)business date 2.shell script must out put .xls or .csvfile as out put without trimming any column name and... (1 Reply)
Discussion started by: balireddy_77
1 Replies

7. Shell Programming and Scripting

any possible to run sql result and output to file

Hi, I search all post...and no soluation about..if i would like to run a sql statement and output the result to txt file. for example, i usually run "sql" to logon the database and run select statement. Then I need to copy the output into the result.txt. Can I run the script to do this... (7 Replies)
Discussion started by: happyv
7 Replies

8. Shell Programming and Scripting

How to run an SQL script inside a shell

How do I create a K Shell which would silently (without user input) logon to Oracle and run an SQL script? Any help will be greatly appreciated. Steve (1 Reply)
Discussion started by: stevefox
1 Replies

9. Shell Programming and Scripting

can nested SQl be run in Unix Script?

can nested SQl be run in Unix Script? I tried some and found only simply sql(one select) can work well in unix script. (21 Replies)
Discussion started by: YoYo
21 Replies
Login or Register to Ask a Question