Automation, Backup Config Multiple Device
Assalamualaikum! Kita akan lanjut membahas Automation!!
Bagaiman jika device nya lebih dari satu?
Misalkan ada 4 devices, menggunakan IP 192.168.10.2, 192.168.10.3, 192.168.10.4, 192.168.10.5??
Caranya gampang!!
Tinggall tambahkan IP Address di scriptnya!
Berikut scriptnya:
ip_list = ["192.168.10.2","192.168.10.3", "192.168.10.4","192.168.10.5"]
username = "fathan"
password = "fathanrafaa"
ssh_client = paramiko.SSHClient()
ssh_client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
for ip_address in ip_list:
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(4)
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!!\n".format(ip_address)
ssh_client.close()
Pada script commanf ip_list, kita bisa menambahkan IP device lain untuk kita backup, tetapi dengan syarat!
Pastikan username dan passwordnya sama dengan yang di script, agar script bisa berjalan!
Jika kita input ke ubuntu:
root@NetworkAutomation-1:~#nano backupmultiple.py root@NetworkAutomation1:~# cat backupmultiple.py import paramiko import time
ip_list = ["192.168.10.2","192.168.10.3", "192.168.10.4","192.168.10.5"]
username = "fathan"
password = "fathanrafaa"
ssh_client = paramiko.SSHClient()
ssh_client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
for ip_address in ip_list:
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(4)
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!!\n".format(ip_address)
ssh_client.close()
Jika sudah tinggal kita jalankan!
root@NetworkAutomation-1:~# python backupmultiple.py
Success login to 192.168.10.2 Config in 192.168.10.2 saved!!
Success login to 192.168.10.3 Config in 192.168.10.3 saved!!
Success login to 192.168.10.4 Config in 192.168.10.4 saved!!
Success login to 192.168.10.5 Config in 192.168.10.5 saved!!
root@NetworkAutomation-1:~# ls | grep .cfg 192.168.10.2.cfg
192.168.10.3. cfg
192.168.10.4. cfg
192.168.10.5. cfg
Filenya juga sudah tersimpan sesuai IP Addressnya!
mantap bangg
BalasHapus