title: Python subprocess - run multiple shell commands over SSH
body: <p>I am trying to open an SSH pipe from one Linux box to another, run a few shell commands, and then close the SSH.</p>
  
  <p>I don't have control over the packages on either box, so something like fabric or paramiko is out of the question.</p>
  
  <p>I have had luck using the following code to run one bash command, in this case "uptime", but am not sure how to issue one command after another. I'm expecting something like:</p>
  
  <pre><code>sshProcess = subprocess.call('ssh ' + &lt;remote client&gt;, &lt;subprocess stuff&gt;)
  lsProcess = subprocess.call('ls', &lt;subprocess stuff&gt;)
  lsProcess.close()
  uptimeProcess = subprocess.call('uptime', &lt;subprocess stuff&gt;)
  uptimeProcess.close()
  sshProcess.close()
  </code></pre>
  
  <p>What part of the subprocess module am I missing?</p>
  
  <p>Thanks</p>
  
  <pre><code>pingtest = subprocess.call("ping -c 1 %s" % &lt;remote client&gt;,shell=True,stdout=open('/dev/null', 'w'),stderr=subprocess.STDOUT)
  if pingtest == 0:
    print '%s: is alive' % &lt;remote client&gt;
    # Uptime + CPU Load averages
    print 'Attempting to get uptime...'
    sshProcess = subprocess.Popen('ssh '+&lt;remote client&gt;, shell=True,stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
    sshProcess,stderr = sshProcess.communicate()
    print sshProcess
    uptime = subprocess.Popen('uptime', shell=True,stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
    uptimeProcess,stderr = uptimeProcess.communicate()
    uptimeProcess.close( )
    print 'Uptime         : ' + uptimeProcess.split('up ')[1].split(',')[0]
  else:
    print "%s: did not respond" % &lt;remote client&gt;
  </code></pre>