title: How to run shell script as postgres on remote server using fabric python
body: <p>How can I enter postgres sudo user to run a script in a specific folder?
  The reason I have to cd into the script is because it requires me to run it in that particular directory.</p>
  
  <p>Would love inputs and comments on my approach and see if there is a better way.</p>
  
  <p>The following is the fabric script I came up with. but it does't allow me to enter postgres user mode.</p>
  
  <pre><code>@task
  def run():
      with sudo('-su postgres'):
          with cd('/home/XXX/www/my_app'):
              run('somescript.sh', use_sudo=True)
  </code></pre>
  
  <p>Thank you!</p>