title: Print SSH output from Cisco Router to a text file
body: <p>I am a newbie to Python as well as the programming world. After a bit of research for the past 2 days am now able to successfully SSH into the Cisco router and execute set of commands. However my original goal is to print the resultant output to a text file. Checked lots of posts by forum members which helped me in constructing the code, but I couldn't get the result printed on the text file. Please help.</p>
  
  <p>Here is my code:</p>
  
  <pre><code>import paramiko
  import sys
  import os
  
  dssh = paramiko.SSHClient()
  dssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
  dssh.connect('10.0.0.1', username='cisco', password='cisco')  
  stdin, stdout, stderr = dssh.exec_command('sh ip ssh')
  print stdout.read()
  f = open('output.txt', 'a')
  f.write(stdout.read())
  f.close()
  dssh.close()
  </code></pre>