Script to install Oracle client 12c2 on Redhat linux 7.5 Can someone help me to provide a script which I can use to install the Oracle client as part of the server build or AMI. Below script I was able to pull out from  the guide in the Oracle site. But still I am missing something. I have added the main code area. Prerequisites are taken care. 

By this code doesn't work if it is executed as script, due to user change to oracle just before execution of runinstaller and once that is done it continues to throws. But required permission are already granted. Someone please help.

[INS-30131] Initial setup required for the execution of installer validations failed.
   CAUSE: Failed to access the temporary location.
   ACTION: Ensure that the current user has required permissions to access the temporary location.
*ADDITIONAL INFORMATION:*
 - PRVG-1901 : failed to setup CVU remote execution framework directory "/tmp/CVU_12.2.0.1.0_oracle/" on nodes "ip-10-81-140-134"
 - Cause:  An operation requiring remote execution could not complete because the attempt to set up the Cluster Verification Utility remote execution framework failed on the indicated nodes at the indicated directory location because the CVU remote execution framework version did not match the CVU java verification framework version. The accompanying message provides detailed failure information.
 - Action:  Ensure that the directory indicated exists or can be created and the user executing the checks has sufficient permission to overwrite the contents of this directory. Also review the accompanying error messages and respond to them.
Summary of the failed nodes
ip-10-81-140-134


groupadd oinstall
groupadd dba
sudo useradd -g oinstall -G dba oracle; echo Nbst@AWS01 | passwd oracle --stdin
cd /opt
mkdir app
mkdir app/oracle
chown oracle:oinstall app
chown oracle:oinstall app/oracle
cd /tmp

wget https://amazonaws.com/linuxx64_12201_client.zip
chown oracle:oinstall linuxx64_12201_client.zip
unzip linuxx64_12201_client.zip
chown oracle:oinstall client
cd /tmp/client/
wget https://amazonaws.com/client_install.rsp
chown oracle:oinstall client_install.rsp 
chmod 775 client_install.rsp
sudo su oracle; echo Nbst@AWS01 | passwd oracle --stdin 
export ORACLE_BASE=/opt/app/oracle
export ORACLE_HOME=/opt/app/oracle/product/12.2.0/client_1
/tmp/client/runInstaller -silent -responseFile /tmp/client/client_install.rsp
exit
cd /opt/app/oraInventory/
./orainstRoot.sh
cd /opt/app/oralinventory/
./orainstRoot.sh

cd /opt/app/oracle/product/12.1.0/client_1/network/admin/
wget https://amazonaws.com/tnsnames.ora
chown oracle:oinstall tnsnames.ora
chmod 775 tnsnames.ora
That will not work, that is not how you execute commands as an other user. + Only root can run passwd username, not even oracle user can run passwd oracle.

sudo su oracle; echo Nbst@AWS01 | passwd oracle --stdin 
export ORACLE_BASE=/opt/app/oracle
export ORACLE_HOME=/opt/app/oracle/product/12.2.0/client_1
/tmp/client/runInstaller -silent -responseFile /tmp/client/client_install.rsp
exit


Use something like this:

echo Nbst@AWS01 | passwd oracle --stdin
sudo su oracle -c "export ORACLE_BASE=/opt/app/oracle;
export ORACLE_HOME=/opt/app/oracle/product/12.2.0/client_1;
/tmp/client/runInstaller -silent -responseFile /tmp/client/client_install.rsp"