简体   繁体   English

从根目录运行一个脚本,它会调用sudo oracle中的另一个脚本。 如何做到这一点而无需询问oracle的密码

[英]Run a script from root and it calls another script that was in the sudo oracle. how to do that without asking the password of the oracle

I'm logging into a linux machine with root and after login i have used su - oracle to connect my database. 我使用root用户登录到linux计算机,登录后我使用su-oracle连接我的数据库。 Now I've 2 shell scripts one at root home and one at home/oracle. 现在,我有2个Shell脚本,其中一个位于root home,另一个位于home / oracle。 In the home/oracle I've wrote a script for taking the backup of the database. 在home / oracle中,我编写了一个脚本来获取数据库的备份。 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. 根目录中可用的脚本是nohup ssh oracle @ onprem-svcdb /home/oracle/test.sh,在运行脚本时会询问oracle的密码,在运行脚本时不需要这样,它不需要不需要询问密码,它需要在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. 如果不需要密码提示,则需要在Linux计算机中为登录用户生成ssh的公用密钥和专用密钥,并在数据库中进行配置。 Please have a look at the below link 请看下面的链接

http://docs.oracle.com/cd/E19253-01/816-4557/sshuser-33/index.html 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 来源: 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: 您将在下面启动Expect脚本,该脚本将作为回报启动您的主sql脚本,并在出现提示时发送oracle密码:

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 如何安装: http//www.cyberciti.biz/tips/execute-commands-on-multiple-hosts-using-expect-tool-part-iii.html

Or you could try to modify visudo , like : 或者您可以尝试修改visudo,例如:

user1    ALL=(user2) NOPASSWD: /bin/bash

where : user1 will be granted "su to user2" without password prompt. 其中:user1将被授予“ su to user2”,而不会出现密码提示。 You can replace also /bin/bash by ALL and then you could launch any command as user2 您也可以用ALL替换/ bin / bash,然后可以以user2身份启动任何命令

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM