title: How to switch to different user inside a shell script and execute some command with the new user?
body: <p>I am currently logged into "SERVER1" with user "USER1", and i have placed my bash script here. This script has to switch to different user "USER2" on the same server "SERVER1" and execute some commands with the new switched user.</p>
  
  <p>Note: USER1 is not a root user, so i need to specify the USER2 password inside the script, but in a encrypted format.</p>
  
  <p>Please help me in achieving this..!</p>
  
  <pre><code>#!/bin/bash
  
  command1
  command2
  .
  .
  ...
  
  echo "PASSWORD" | su USER2 &lt;&lt; EOF
  command1
  command2
  .
  .
  ...
  </code></pre>
  
  <p>Please note, i don't want to change any configuration files here to achieve this.  </p>