Running batch commands on remote junos devices

I am sure from time to time you need to run an operational command on multiple junos devices e.g deleting a specific file from all devices. It is up to you of course what sort of commands you can run. For the following script to work you should also install python paramiko module. You may possibly install this module on a linux system via the command “pip install paramiko” . I have also attached the script here as some characters may not be displayed properly in this post. Now let me explain how to use this script.

Once you save the script with the name junos_cmd.py, there are two types of execution

1) Single command on a single system

This command will run the command “file delete /tmp/test.txt” on the device having ip 192.168.1.1 (root user should be used for this command to work)

2) Single command on multiple systems

This command will fetch all ip addresses written in the file /tmp/ipaddr.txt (each ip should be in a new line) and run the operational command one by one.

This is a very basic script but it may shed you some light to develop your own complex scripts. I also use it to fetch command outputs and then interpret the outputs via python again. Let me know if you need any help in using it.

You have a feedback?