title: Pipe script and binary data to stdin via ssh
body: <p>I want to execute a bash script remotely which consumes a tarball and performs some logic to it. The trick is that I want to use only one ssh command to do it (rather than <code>scp</code> for the tarball followed by <code>ssh</code> for the script).</p>
  
  <p>The bash script looks like this:</p>
  
  <pre><code>cd /tmp
  tar -zx
  ./archive/some_script.sh
  rm -r archive
  </code></pre>
  
  <p>I realize that I can simply reformat this script into a one-liner and use</p>
  
  <pre><code>tar -cz ./archive | ssh $HOST bash -c '&lt;commands&gt;'
  </code></pre>
  
  <p>but my actual script is complicated enough that I must pipe it to <code>bash</code> via stdin. The challenge here is that <code>ssh</code> provides only one input pipe (stdin) which I want to use for both the bash script and the tarball.</p>