Blogs

Scripting How-To: Save the active configuration in a text file

By tmoovana posted 05-03-2016 08:44

  

Question

How do I save the active configuration in a text file without modifying the rescue configuration?

Answer

 

You can use the Secure Copy (scp) feature to copy the file to a directory.

 

/config/juniper.conf.gz

This is a gzipped text file and you can ungzip the file when you need it.

 

Alternatively, you can write a script similar to the following. This script gets the output of the  show configuration command as a string and saves it in a text file.

 

from jnpr.junos import Device
####Connect to Device
dev = Device(host='192.168.56.2', user='root', password='Juniper1')
#192.168.56.2
dev.open()

class Create_Config():
def __init__(self):
config=str(self.get_conf()) ####Get Config as Str

#####Create/Write to Config to File
with open("Config.config", "w") as text_file:
text_file.write(config)
text_file.close()
#####Return Configuration
def get_conf(self):
return dev.cli("show configuration")


run=Create_Config()

 


#How-To