cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
2027
Views
0
Helpful
1
Replies

Problem with running cli commands with " over ssh using paramiko and python

zerocool443
Cisco Employee
Cisco Employee

So what i am trying to achieve with the script is few counters for health checks of UC devices.

 

To do so i am using paramiko lib with python to issue cli commands  over ssh and return the output.

This scripts works perfectly fine with commands that do no include escape character. for example retriving output of show staus works completely fine.

 

but let say i wan to run a command like this. : show perf query counter "Cisco XCP CM"  "CmConnectedSockets"

 

For the above mentioned command the script fails saying the command entered is incorrect.

 

Here is the code snippet.

 

client = paramiko.SSHClient()
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
client.connect(cucm_pub_ip, username=username, password=password, look_for_keys=False, allow_agent=False)

# SSH connection established to - ip
time.sleep(5)

command = "show perf query counter \"Cisco XCP CM\" \"CmConnectedSockets\" \n"

 

stdin_, stdout_, stderr_ = client.exec_command(command)
time.sleep(15)
stdout_.channel.recv_exit_status()
for x in stdout_.readlines():
 print x

 

------------------------------------------------------------------

 

2nd method

 

ucos_shell = client.invoke_shell()
# -- Invoked Interactive Shell

time.sleep(5)

output = ucos_shell.recv(5000)
print output

ucos_shell.send("show perf query counter \"Cisco XCP CM\" \"CmConnectedSockets\" \r")
time.sleep(15)

output = ucos_shell.recv(200000)
print output

 

----------------------------------------------------

What all i have tried to make this work but didn't succeed.

> changing the string formats

>escaping characters like '  " 

>changing the python versions

>using both functions available to execute command i.e  (....send(...)   and   ....exec_command() )

 

Any help would be appreciated.

1 Reply 1

Anthony Holloway
Cisco Employee
Cisco Employee
Any reason you're not using the Perform API?

https://developer.cisco.com/site/sxml/discover/overview/perfmon/