Automation
Automation

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

by Juniper Employee on ‎05-03-2016 08:44 AM - edited on ‎08-23-2017 12:01 PM by Administrator Administrator (2,147 Views)

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()