So let's iterate our script and get it to do something else.
Here's a new version of the script and I've made some changes.
We don't need this sort of removed that from the script that says Enter your remote account.
I've changed that back to enter your telnet username because that makes more sense.
This is the same as before.
We asking the user for a password and we opening up a file called my switches for each IP address in
the file.
We're going to strip any spaces and then we're going to print a get a running config from switch.
So I've made a slight change here.
Rather than making changes to the VLAN database of the switches.
I'm going to use the command terminal length zero and show run to show the running configuration of
the switches.
So I've added a print statement here so that we know that the script is getting the running configuration
from a switch.
Was this IP address?
So rather than saying configuring switch, it's now going to say getting running config from the switch.
The rest of the code is very similar.
So telnet into the switch.
And a logging in is the same as the previous script, but we're not going to type confetti.
We simply going to type terminal length zero and show run.
The reason for doing that.
Is when you telnet to a switch and you type show run by default.
We only getting 24 lines of output and I have to press spacebar.
To show each page of output.
So show.
Run.
Press spacebar.
Press spacebar again and so forth to see the rest of the configuration.
And I need to do that multiple times to view the entire running configuration.
So rather than doing that, I'm going to type terminal length, zero show run and that will show us
the entire running configuration in one go.
It's all set to the length back to 24 of the default.
But when the script telnet to the switch, it's going to type terminal length, a zero show run, get
the entire running configuration and then exit out of the Telnet session.
But it's not only going to do that, we're going to take the output and save that to a file.
So I've got this variable called save output.
We're going to open up a file called Switch, followed by the hostname, which is essentially the IP
address of the switch.
And we're going to open the file as a reader.
Right.
So save output.
Right.
What are we going to write?
We're going to write the output of the Telnet session in ASCII format.
We're going to press carriage return and close the file.
Now we can print the output to the screen, but we don't need to do that.
We'll simply save the configuration to a file.
So again, we are iterating our scripts and improving them.
So let's copy that script.
On the network automation container.
Let's create a file called Back Up Configs dot py.
And I'll save that script to the file.
So again, cat back up configs.
P There's our script.
Now, before I run the script and notice that there are no files on the network automation container.
That have the name switch followed by IP address.
So after the moment, we only have our Python scripts.
But if I type Python three back up configs, specify my username and password.
The script is now telling, heading to the individual switches and is grabbing the running configuration.
And is saving that as files under the network automation container.
It's now completed.
So Liz shows us these files.
So more switch and let's look at 83.
You can see that this is the running configuration of the switch.
Space Bar shows us the configuration of the switch.
Again, we could look at another switch, let's say switch six.
There's the running configuration of the switch.
Now you could edit the output and get rid of this kind of output.
I'm not doing that at the moment.
I simply want to back up the running configuration of the switches to the network automation container.
Notice the power of network automation.
I'll remove all files that were backed up and then I'll simply run the script again.
So I'm running the script and getting it to telnet to the switches and getting it to save.
The running configurations in this directory.
Liz shows us the running configurations.
So again, more switch.
Let's look at 72.
There's the configuration of switch one with IP address 1921681 2272.
We could look at A2.
There's the configuration of that switch.
So it's not very difficult to use Python to back up the configurations of your network devices.
The script is only 27 lines in length.
It's a very short script but does something very useful.
It telnet to network devices and retrieves the running configuration of those network devices.