title: Kill next command in pipeline on failure
body: <p>I have a streaming backup script which I'm running as follows:</p>
  
  <pre><code>./backup_script.sh | aws s3 cp - s3://bucket/path/to/backup
  </code></pre>
  
  <p>The <code>aws</code> command streams stdin to cloud storage in an atomic way. If the process is interrupted without an EOF, the upload is aborted.</p>
  
  <p>I want the <code>aws</code> process to be killed if <code>./backup_script.sh</code> exits with a non-zero exit code.</p>
  
  <p>Any bash trick for doing this?</p>
  
  <p>EDIT:
  You can test your solution with this script:</p>
  
  <pre><code>#!/usr/bin/env python
  import signal
  import sys
  import functools
  
  def signal_handler(signame, signum, frame):
      print "Got {}".format(signame)
      sys.exit(0)
  
  signal.signal(signal.SIGTERM, functools.partial(signal_handler, 'TERM'))
  signal.signal(signal.SIGINT, functools.partial(signal_handler, 'INT'))
  
  for i in sys.stdin:
      pass
  
  print "Got EOF"
  </code></pre>
  
  <p>Example:</p>
  
  <pre><code>$ grep --bla | ./sigoreof.py
  grep: unrecognized option `--bla'
  usage: grep [-abcDEFGHhIiJLlmnOoqRSsUVvwxZ] [-A num] [-B num] [-C[num]]
      [-e pattern] [-f file] [--binary-files=value] [--color=when]
      [--context[=num]] [--directories=action] [--label] [--line-buffered]
      [--null] [pattern] [file ...]
  Got EOF
  </code></pre>
  
  <p>I want <code>./sigoreof.py</code> to be terminated with a signal.</p>