title: How can you automate terminal commands?
body: <p>I'm tired of doing this.</p>
  
  <pre><code>ssh me@somehost.com
  input my password
  sudo su - someuser
  input my password
  cd /some/working/directory
  &lt;run some commands&gt;
  </code></pre>
  
  <p>Is there anyway to automate this? Do I need a special shell? or a shell emulator? can I programmatically drive the shell up to certain point then <strong>run manual commands on it</strong>?</p>
  
  <p>Bonus points of it's programmed in python for extra hacking goodness</p>
  
  <p>edit: All the answers below focus on the "full automation" part of the question: Where the hard part is what I highlighted above. Here is another example to see if I can capture the essence. </p>
  
  <pre><code>ssh me@somehost.com
  &lt;get a shell because keys are setup&gt;
  sudo su - user_that_deploys_the_app
  &lt;input password, because we don't want to give passwordless sudo to developers&gt;
  cd env; source bin/activate
  cd /path/where/ur/app/is/staging
  &lt;edit some files, restart the server, edit some more, check the logs, etc.&gt;
  exit the term
  </code></pre>