title: Paramiko and exec_command - killing remote process?
body: <p>I'm using Paramiko to <code>tail -f</code> a file on a remote server.</p>
  
  <p>Previously, we were running this via <code>ssh -t</code>, but that proved flaky, and the <code>-t</code> caused issues with our remote scheduling system.</p>
  
  <p>My question is how to kill tail when the script catches a SIGINT?</p>
  
  <p>My script (based on <a href="https://stackoverflow.com/questions/760978/long-running-ssh-commands-in-python-paramiko-module-and-how-to-end-them">Long-running ssh commands in python paramiko module (and how to end them)</a>)</p>
  
  <pre><code>#!/usr/bin/env python2
  import paramiko
  import select
  
  client = paramiko.SSHClient()
  client.load_system_host_keys()
  client.connect('someserver', username='victorhooi', password='blahblah')
  transport = client.get_transport()
  channel = transport.open_session()
  
  channel.exec_command("tail -f /home/victorhooi/macbeth.txt")
  while True:
      try:
          rl, wl, xl = select.select([channel],[],[],0.0)
          if len(rl) &gt; 0:
              # Must be stdout
              print channel.recv(1024)
      except KeyboardInterrupt:
          print("Caught control-C")
          client.close()
          channel.close()
          exit(0)
  </code></pre>
  
  <p>The script catches my <kbd>Ctrl-C</kbd> successfully, and ends. However, it leaves the <code>tail -f</code> process running on the remote system,.</p>
  
  <p>Neither client.close() nor channel.close() seem to terminate it.</p>
  
  <p>What command can I issue in the except block to kill it?</p>
  
  <p>The remote server is running Solaris 10.</p>