Operating System - Linux
1748103 Members
4814 Online
108758 Solutions
New Discussion юеВ

Re: Asking for user password while running a script

 
SOLVED
Go to solution

Asking for user password while running a script

I'm creating a script to auto start my oracle listener and open a startup the database automatically. Below is the script

#!/bin/sh
su -oracle
export ORACLE_HOME=/cramerapps/oracleAS
echo $ORACLE_HOME
export ORACLE_SID=asdb
lsnrctl start
sqlplus "sys/syspassword @ asdb as sysdba" <startup
exit
EOF
~

But after executing, the script will prompt for oracle password. How to skip the password prompt? How can i put the password into the script??
5 REPLIES 5
Steven E. Protter
Exalted Contributor

Re: Asking for user password while running a script

Shalom,

http://www.orafaq.com/forum/t/37241/0/

http://www.adp-gmbh.ch/ora/misc/read_sql_from_shell_script.html

http://www.dbasupport.com/forums/archive/index.php/t-8424.html

http://www.unix.com/showthread.php?t=17437

SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
Sundar_7
Honored Contributor

Re: Asking for user password while running a script

Why do you even need to su ? Are you not executing the script as user "oracle" ?
Learn What to do ,How to do and more importantly When to do ?
linuxfan
Honored Contributor

Re: Asking for user password while running a script

Hi,

Who will be executing this script?

If root is running it then you don't need a password. If a non-root user is running the script then one of the option is to to setup sudo.
They think they know but don't. At least I know I don't know - Socrates

Re: Asking for user password while running a script

the script run by user root. but the command is only applicable for user oracle. How to use sudo?
SANTOSH S. MHASKAR
Trusted Contributor
Solution

Re: Asking for user password while running a script

Hi,

Firstly OS password cannot be embedded in scripts,
Also if oracle user is (which I assume as oracle software owner and oracle db release >= 9i) script owner, then no
need to provide sys/syspasswd

U can do like this,

login as oracle

create ur script say Start_db_lsnr.sh as

!# /usr/bin/ksh

export ORACLE_HOME=/cramerapps/oracleAS
export ORACLE_SID=asdb
$ORACLE_HOME/bin/lsnrctl start
$ORACLE_HOME/bin/sqlplus "/as sysdba" <startup
exit
EOF

if root is invoking this script then use

# su - oracle -c

for any other user use sudo to give access for this script to
other users

http://hpux.connect.org.uk/hppd/hpux/Sysadmin/sudo-1.6.8p12/


for this u have to configure /etc/sudoers using visudo command as root

# visudo

..

...

= (oracle) NOPASSWD:
..
..

save and exit

now login as and execute as

sudo

- Santosh