linux - 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 linux machine root , after login have used su - oracle connect database. i've 2 shell scripts 1 @ root home , 1 @ home/oracle. in home/oracle i've wrote script taking backup of database. script available in root nohup ssh oracle@onprem-svcdb /home/oracle/test.sh while running script asking password of oracle, don't need while running scripts doesn't need ask password , needs run script in oracle. need that??? can this
you try expect tool:
you start expect script below, start main sql-script in return , send oracle password if prompted:
content of /tmp/expect.exp script: #!/usr/bin/expect -f # set variables set password '***' set timeout -1 # execute spawn /usr/bin/su oracle -c "/tmp/main_script.sh" match_max 100000 # passwod prompt while {1 > 0 } { expect "*?assword:*" # send password aka $password send -- "$password\r" } # send blank line (\r) make sure gui send -- "\r" expect eof than main script stored in (or root home, whatever dir need):
/tmp/main_script.sh content: su - oracle drop table; create table; other sql commands one disadvantage - plain text password, stored inside script
how install: http://www.cyberciti.biz/tips/execute-commands-on-multiple-hosts-using-expect-tool-part-iii.html
or try modify visudo , :
user1 all=(user2) nopasswd: /bin/bash where : user1 granted "su user2" without password prompt. can replace /bin/bash , launch command user2
Comments
Post a Comment