greholidays.blogg.se

Download cisco switch auto backup config tftp
Download cisco switch auto backup config tftp





download cisco switch auto backup config tftp

Line 29 creates a list that is used to store the content we get back from the router. Lines 27–28 make the connection to the device and execute the "show run" command.

download cisco switch auto backup config tftp

Line 25 begins a loop to read the values from the list, and line 26 strips any extra character, such as carriage returns or line feeds. Line 18 closes the file once all values are read. Lines 20–22 open the device file using the variable name and read the contents into a list called iplist that we will use in the next section of code. Be sure to provide the full path to the file. This is required to escape the backslash character. Notice the double backslashes in the file path. I have variables to represent the file paths to our input text file as well as the location where we will store the backup files of the Cisco config. I try to use variable names that make sense and make it easy to figure out what they represent. Using variables makes our program easier to read and gives it more flexibility. Lines 14–17 define some variables we will use in our script. We use the datetime function to give us a timestamp for our filename. Lines 4–11 import Paramiko and the time module and set up the SSH parameters for Paramiko. Here is the breakdown of each line in the script: Outfile = open(outfilepath + ipaddr + "_" + time_now, "w") Stdin, stdout, stderr = ssh.exec_command('show run') Ssh.connect(hostname=ipaddr, username=user, password=secret, port=port) # loop through device list and execute commands Input_file = open( infilepath + devicelist, "r") Outfilepath = "c:\\Users\\johnk\\Downloads\\" Infilepath = "c:\\Users\\johnk\\Downloads\\" Ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy()) # import modules needed and set up ssh connection parameters Cisco config backup Python script # Backup Cisco config I have an explanation of each line after the code. Python ignores white space, but it makes it easier to read and understand. I have added comments and broken them into sections, separating the lines with a line of white space. Much of this was used in the previous script.

download cisco switch auto backup config tftp

Now, let us have a look at the script we will use.







Download cisco switch auto backup config tftp