title: How to use su command from within ssh command in unix shell script
body: <p>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. </p>
  
  <p>1.)I used the following code to ssh into the machine and give the expected pwd to login into this machine.</p>
  
  <pre><code>DSADMINPWD=dsadminpwd
  PWD=pwd
  /usr/bin/expect&lt;&lt;EOD
  spawn ssh -oStrictHostKeyChecking=no -oCheckHostIP=no &lt;username&gt;@&lt;remotemachineurl&gt;
  expect "password"
  send "$PWD\n"
  EOD
  </code></pre>
  
  <p>The above works fine. But while doing su dsadmin after this. I am unable to go inside that
  user from the previously taken password.</p>
  
  <p>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.</p>
  
  <pre><code>    DSADMINPWD=dsadminpwd
      PWD=pwd
      /usr/bin/expect&lt;&lt;EOD
      spawn ssh -oStrictHostKeyChecking=no -oCheckHostIP=no &lt;username&gt;@&lt;remotemachineurl&gt;
      expect "password"
      send "$PWD\n"
      EOD
  
      su dsadmin
      &lt;like to make some folders in dsadmin directory&gt;
      exit... 
  </code></pre>
  
  <p>After doing su dsadmin it will come as </p>
  
  <pre><code>   bash-3.00$
  </code></pre>
  
  <p>No sign of password or anything here.</p>
  
  <p>From the above it is not working</p>
  
  <p>Could you please suggest if anything is possible to make su  after ssh with password in automated script. Any suggestions would be highly appreciated.</p>
  
  <p>Thanks!</p>