Running a CLI command from Python using paramiko

Showing results for 
Show  only  | Search instead for 
Did you mean: 

Running a CLI command from Python using paramiko

L1 Bithead

I have a very simple python script that uses ssh=paramiko.SSHClient(), ssh.connect (host, 22, user, password), stdin, stdout, stderr=ssh.exec_command(command), and for line in print(line). 

When I set host, user, password and command, e.g. "show ip int brief", to connect to a Cisco router, everything works fine and the script prints out the results that I expect. However, when I set them to connect to a PAN firewall, e.g. command="show clock", my script connects to the FW, which I confirm by looking in the FW's system log, but all I get returned is the 'Number of failed attempts since last successful login: 0' message?


Any ideas - I'm sure I'm just missing something basic. Do I need to import any of the PAN packages or can I just run run simple CLI commands using paramiko?


PS: I sleep for 20 seconds after connecting before running the ssh.exec_command()





L1 Bithead

Solved by:

import pandevice
my_fw = firewall.Firewall(host, user, password)
response = my_fw.op(command2, xml=True)


The response is a page of XML, so needs to be interpreted, but I do get the answers I want 🙂

  • 1 replies
Like what you see?

Show your appreciation!

Click Like if a post is helpful to you or if you just want to show your support.

Click Accept as Solution to acknowledge that the answer to your question has been provided.

The button appears next to the replies on topics you’ve started. The member who gave the solution and all future visitors to this topic will appreciate it!

These simple actions take just seconds of your time, but go a long way in showing appreciation for community members and the LIVEcommunity as a whole!

The LIVEcommunity thanks you for your participation!