11-05-2018 06:50 AM
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.
11-08-2018 11:07 AM
Discover and save your favorite ideas. Come back to expert answers, step-by-step guides, recent topics, and more.
New here? Get started with these tips. How to use Community New member guide