Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python
- import paramiko, time, datetime, sys, os
- def disable_paging(remote_conn):
- remote_conn.send("terminal length 0\n")
- time.sleep(1)
- output = remote_conn.recv(1000)
- return output
- def ssh_conn(ip,username,password,customer,hostname):
- remote_conn_pre = paramiko.SSHClient()
- remote_conn_pre.set_missing_host_key_policy(
- paramiko.AutoAddPolicy())
- remote_conn_pre.connect(ip, username=username, password=password)
- remote_conn = remote_conn_pre.invoke_shell()
- output = remote_conn.recv(1000)
- disable_paging(remote_conn)
- remote_conn.send("show run\n")
- time.sleep(2)
- output = remote_conn.recv(5000)
- cust_dir = '../backup_configs/' + customer
- if not os.path.exists(cust_dir):
- os.makedirs(cust_dir)
- t = time.strftime("%Y-%m-%d-%H:%M")
- sys.stdout = open("../backup_configs/"+ customer +"/"+ t + "_" + hostname +".backup", "w")
- print output
Advertisement
Add Comment
Please, Sign In to add comment