cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
689
Views
2
Helpful
1
Replies

Read/Pull/Fetch multiple "show commands" out multiple ios devices

Odys (CSC)
Level 1
Level 1

I'd like to share with you this simple and handy script I've written recently without weird and complex symbols and codes.

I hope you find it useful too.

here is how it works:

1- Import the Netmiko package/module for network automation.

2- Input the mgmt ip addresses as a file. (file1)

3- Input the commands as a file.  (file2)

4- iterate over all devices, 1 by 1.

5- Input the device information (type, ip, user, pass) by using a dictionary (dict)

6- connect to the current device in dict by using ssh

7- iterate over all commands for the current device in dect. and print the output

Of course, this script can be leveled up with some arranging codes, as this is only the base working code.

Again; I hope you like it and find it useful.

If interested, I'll write and post a script making config changes from an external file.

 

 

 

 

from netmiko import Netmiko

with open('addresses.txt') as f1:
    file1 =f1.read().splitlines()

with open('commands.txt') as f2:
    file2 =f2.read().splitlines()

for device in file1:
    dict = {'device_type':'cisco_ios',
       'ip':device,
       'username':'user1',
       'password':'secret1'
    }
    ssh = Netmiko(**dict)
    for cmd in file2:
        output = ssh.send_command(cmd)
        print(output)

 

 

 

 

1 Reply 1

Alexander Stevenson
Cisco Employee
Cisco Employee

Thanks for sharing!