My Requirement is to login into the remote machine and make some folders for this I am planning to take username and pwd as input from the user and try to make automate shell script.
1.)I used the following code to ssh into the machine and give the expected pwd to login into this machine.
DSADMINPWD=dsadminpwd
PWD=pwd
/usr/bin/expect<<EOD
spawn ssh -oStrictHostKeyChecking=no -oCheckHostIP=no <username>@<remotemachineurl>
expect "password"
send "$PWD\n"
EOD
The above works fine. But while doing su dsadmin after this. I am unable to go inside that user from the previously taken password.
2.) I have to change user like su dsadmin from inside this machine. Also there is a password for dsadmin. But it is not working properly.
DSADMINPWD=dsadminpwd
PWD=pwd
/usr/bin/expect<<EOD
spawn ssh -oStrictHostKeyChecking=no -oCheckHostIP=no <username>@<remotemachineurl>
expect "password"
send "$PWD\n"
EOD
su dsadmin
<like to make some folders in dsadmin directory>
exit...
After doing su dsadmin it will come as
bash-3.00$
No sign of password or anything here.
From the above it is not working
Could you please suggest if anything is possible to make su after ssh with password in automated script. Any suggestions would be highly appreciated.
Thanks!