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