繁体   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

我使用root用户登录到linux计算机,登录后我使用su-oracle连接我的数据库。 现在,我有2个Shell脚本,其中一个位于root home,另一个位于home / oracle。 在home / oracle中,我编写了一个脚本来获取数据库的备份。 根目录中可用的脚本是nohup ssh oracle @ onprem-svcdb /home/oracle/test.sh,在运行脚本时会询问oracle的密码,在运行脚本时不需要这样,它不需要不需要询问密码,它需要在oracle中运行脚本。 我需要为此做些什么??? 谁能帮忙

据我了解,您会收到有关使用脚本的密码提示,该脚本连接到数据库并执行某些操作。 如果不需要密码提示,则需要在Linux计算机中为登录用户生成ssh的公用密钥和专用密钥,并在数据库中进行配置。 请看下面的链接

http://docs.oracle.com/cd/E19253-01/816-4557/sshuser-33/index.html


您可以尝试以下

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

来源: https : //asktom.oracle.com/pls/asktom/f?p=100 :11:0 ::::: P11_QUESTION_ID: 142212348066

您可以尝试期望工具:

您将在下面启动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

比您的主脚本将存储在(或根目录,无论您需要什么目录):

/tmp/main_script.sh content:
su - oracle
drop table; create table; other SQL commands

一个缺点是-纯文本密码,存储在脚本中

如何安装: http//www.cyberciti.biz/tips/execute-commands-on-multiple-hosts-using-expect-tool-part-iii.html

或者您可以尝试修改visudo,例如:

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

其中:user1将被授予“ su to user2”,而不会出现密码提示。 您也可以用ALL替换/ bin / bash,然后可以以user2身份启动任何命令

暂无
暂无

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

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