Backup Config with Paramiko
Ubuntu
root@NetworkAutomation-1:~# cp paramiko1.py backup.py
root@NetworkAutomation-1:~# nano backup.py
root@NetworkAutomation-1:~# cat backup.py
import paramiko import time
ip_address = "192.168.10.2"
username = "cisco"
password = "cisco123"
ssh_client = paramiko.SSHClient()
ssh_client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh_client.connect(hostname=ip_address,username=username,
password=password)
print "Success login to {0}".format(ip_address)
conn = ssh_client.invoke_shell()
conn.send("terminal length 0\n")
conn.send("show run\n") time.sleep(5)
output = conn.recv(65535)
output_file=open("{0}.cfg".format(ip_address),"w") output_file.write(output)
output_file.close()
print "Config in {0} saved!!".format(ip_address)
ssh_client.close()
Ubuntu
root@NetworkAutomation-1:~# python backup.py
Success login to 192.168.10.2
Config in 192.168.10.2 saved!!
root@NetworkAutomation-1:~# ls | grep .cfg 192.168.10.2.cfg
Ubuntu
root@NetworkAutomation-1:~# more 192.168.10.2.cfg
R1#terminal length 0
R1#show run
Building configuration...
Current configuration : 1280 bytes
!
version 12.4
service timestamps debug datetime
msec service timestamps log
datetime msec no service
password-encryption
!
hostname R1
!
boot-startmarker
boot-endmarker
Tidak ada komentar:
Posting Komentar