Python script to execute CLI commands via SSH on multiple devices


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


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:


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



  1. i have an expert mode in my case and i need to send a password and run commands in expert mode. can you help me with this code ?

  2. How do I open 50 simultaneous SSH sessions for the same device and send commands to it at the same time ?

Leave a Reply

Your email address will not be published.