Problems with sudo inside expect script

I run the following script

#!/usr/bin/expect -f set user [lindex $argv 0] set pass [lindex $argv 1] set PATH [lindex $argv 2] set INV_PATH [lindex $argv 3] spawn ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no $user@localhost expect "assword: " send "$pass\r" expect "$ " send "echo $pass | /usr/local/bin/sudo -S $INV_PATH/orainstRoot.sh\r" expect "$ " send "cd $PATH/bin\r" expect "$ " send "echo $pass | /usr/local/bin/sudo -S cp oraenv coraenv sqlplus dbhome /usr/bin\r" expect "$ " send "echo $pass | /usr/local/bin/sudo -S $PATH/root.sh\r" expect "Check" send "\r" 

It works fine on some machines , and for some machines it throws the following error ... I checked, this is not the PATH problem causing the problem.

 /usr/local/bin/sudo: /scratch/prod_sw/app/oraInventory/orainstRoot.sh: command not found $ echo PASSWD | /usr/local/bin/sudo -S cd /scratch/prod_sw/app/prod_sw/product/11.2.0/db_home/bin /usr/local/bin/sudo: cd: command not found $ echo PASSWD | /usr/local/bin/sudo -S cp oraenv coraenv sqlplus dbhome /usr/bin cp: cannot stat `oraenv': No such file or directory cp: cannot stat `coraenv': No such file or directory cp: cannot stat `sqlplus': No such file or directory cp: cannot stat `dbhome': No such file or directory $ echo PASSWD | /usr/local/bin/sudo -S /scratch/prod_sw/app/prod_sw/product/11.2.0/db_home//root.sh Check /scratch/prod_sw/app/prod_sw/product/11.2.0/db_home/install/root_slcad22rhu_2013-07-22_04-41-49.log for the output of root script 
+4
source share
1 answer

Try to specify the full path for these files and mark once.

cp / path / oraenv / path / coraenv / path / sqlplus / path / dbhome / usr / bin

+1
source

Source: https://habr.com/ru/post/1492690/


All Articles