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 ,

I would be greatfull to you experts if you could suggest me how to proceed.

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.

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...

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.

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.

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 :slight_smile:

Cheers,
Cameron