Python script to execute CLI commands via SSH on multiple devices

Scenario

You manage large amount of devices and you want to execute commands and gather output from them in an automated way.

Solution

Use the following Python script. The script uses a CSV file with the following device information:

The script can be executed from shell against a CSV file:

This example script will display an output of ‘show interfaces’ command from all devices listed in the CSV file:

Result

You will receive command output from all devices listed in the CSV file. Let me know in the comments if there are any issues!

Refererence:

http://www.paramiko.org/

Leave a Reply

Your email address will not be published. Required fields are marked *