claumagagnotti

cisco.py

Feb 11th, 2016
305
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.93 KB | None | 0 0
  1. #!/usr/bin/python
  2. import paramiko, time, datetime, sys, os
  3.  
  4. def disable_paging(remote_conn):
  5.     remote_conn.send("terminal length 0\n")
  6.     time.sleep(1)
  7.     output = remote_conn.recv(1000)
  8.     return output
  9.  
  10. def ssh_conn(ip,username,password,customer,hostname):
  11.     remote_conn_pre = paramiko.SSHClient()
  12.     remote_conn_pre.set_missing_host_key_policy(
  13.          paramiko.AutoAddPolicy())
  14.  
  15.     remote_conn_pre.connect(ip, username=username, password=password)
  16.     remote_conn = remote_conn_pre.invoke_shell()
  17.     output = remote_conn.recv(1000)
  18.     disable_paging(remote_conn)
  19.     remote_conn.send("show run\n")
  20.     time.sleep(2)
  21.     output = remote_conn.recv(5000)
  22.     cust_dir = '../backup_configs/' + customer
  23.     if not os.path.exists(cust_dir):
  24.       os.makedirs(cust_dir)
  25.     t = time.strftime("%Y-%m-%d-%H:%M")
  26.     sys.stdout = open("../backup_configs/"+ customer +"/"+ t + "_" + hostname +".backup", "w")
  27.     print output
Advertisement
Add Comment
Please, Sign In to add comment