I'm logging into a linux machine with root and after login i have used su - oracle to connect my database. Now I've 2 shell scripts one at root home and one at home/oracle. In the home/oracle I've wrote a script for taking the backup of the database. The script available in the root is nohup ssh oracle@onprem-svcdb /home/oracle/test.sh while running the script its asking the password of the oracle, I don't need it to be like this while running the scripts It doesn't need to ask the password and it needs to run the script in oracle. What I need to do for that??? Can anyone help for this
If I understand corrently, you are getting a password prompt on using a script which connects to your database and executes something. If you dont need a password prompt , you would need to generate public and private keys for ssh for the logged in user , in your linux machine and get it configured in the database. Please have a look at the below link
http://docs.oracle.com/cd/E19253-01/816-4557/sshuser-33/index.html
You can try the below
Let this be you env variables.
---------VARIABLES --------------
export APP_USER=something
export APP_PASS=somepass
export APP_SID=sid
Here is the script with a execute permission.
--------------SCRIPT TO RUN SQL----------
#!/usr/ksh
sqlplus << END_OF_SQL
$APP_USER/$APP_PASS@APP_SID
select * from dual;
END_OF_SQL
exit $?
----------END SCRIPT----------
Source : https://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:142212348066
you could try expect tool:
You will start expect script below, that will start your main sql-script in return and will send oracle password if prompted:
content of /tmp/expect.exp script:
#!/usr/bin/expect -f
# set Variables
set password '***'
set timeout -1
# what to execute
spawn /usr/bin/su oracle -c "/tmp/main_script.sh"
match_max 100000
# Look for passwod prompt
while {1 > 0 } {
expect "*?assword:*"
# Send password aka $password
send -- "$password\r"
}
# send blank line (\r) to make sure we get back to gui
send -- "\r"
expect eof
than your main script will be stored in (or root home, whatever dir you need):
/tmp/main_script.sh content:
su - oracle
drop table; create table; other SQL commands
One disadvantage is - plain text password, stored inside the script
How to install: http://www.cyberciti.biz/tips/execute-commands-on-multiple-hosts-using-expect-tool-part-iii.html
Or you could try to modify visudo , like :
user1 ALL=(user2) NOPASSWD: /bin/bash
where : user1 will be granted "su to user2" without password prompt. You can replace also /bin/bash by ALL and then you could launch any command as user2
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.