I am writing the shell script to automate few tasks. I am logging into the remote server and installing a few packages. But to install I need to get the root access. I am able to login using my credentials with ssh keys. Once I login I need to switch to root, and then it asks for the password. I tried using echo it still asks for the password.
SCRIPT="pwd; ls; echo 'rootpass' | su -; cd ~; pwd; yum -y install <package>"
How can I pass the password on prompt. I need to maintain the same session, so not sure spawn/expect/send is gonna work.
UPDATE: I tried using printf 'rootpass' | ./script.sh, but it is not working.