Copy Run Start

Copy Run Start

A Simple Script to automate running copy run start on many devices at once.


This script is a fairly basic sctipt but will be the basis of mainy others. I will discuss some basic concepts in this article that I will not cover in the others.

The first thing we are going to need to is make sure netmiko is installed. This package is essential for making this automation easy. Read more about netmiko here: netmiko

pip3 install netmiko

The first part of almost any python script are the packages you want to use. I will be using three different libraries for this script. The first package we install is netmiko. From statement is used to import a specific part of a whole package. You can read more about using from and the other packages see the resources link at the top of this article.

from netmiko import ConnectHandler
from datetime import date
#import logging
import os
import re
import sys

Now we set up some variables that will be used in various parts of the script. I defclare them here so that they have a global scope. tdate uses the the date function we imported from datetime Later we use this in some strings, sicne an interger can’t be used in a file name for a variabel it first needs to converted to a string. tdate

The username, password adn enable_sec, are all variables set by getting input from the user at run time. blank_var, is setup as a empty string to be used as place holder in part of our script and gets replaced later on. The last line in this section we take sys.stdout to a variable that we will use later on.

tdate = date.today()
tdate = str(tdate)

username = input(f'Enter Username:')
password = input(f'Enter Password:')
enable_sec = input(f'Enter enable secret:')

blank_var = ''
orig_stdout = sys.stdout

Each line creates a list from a file. The open function takes two paramaters. The first is the name of the file you want to open the second is mode the file is opened with. I have just used ‘r’ to open the file up in read mode. Using the read() funciton to read the file as a string we then pass this to the splitlines() function to read each line into our list. The file(s) I created are formated with one IP address per line.

Leave a Reply