I am using paramiko to establish ssh session and send commands to the server.
Few of the commands are not successfully executed. How do i detect those commands are failed to execute and terminate python code. Below is the code what I am trying :
remote_conn_pre = paramiko.SSHClient()
remote_conn_pre.set_missing_host_key_policy(
paramiko.AutoAddPolicy())
remote_conn_pre.connect(host, username=username, password=password, look_for_keys=False, allow_agent=False)
print "SSH connection established to %s" % host
# Use invoke_shell to establish an 'interactive session'
remote_conn = remote_conn_pre.invoke_shell()
remote_conn.send("\n")
remote_conn.send("scope org engg\n")
remote_conn.send("\n")
remote_conn.send("show service-profile")
if remote_conn.recv_ready():
details = remote_conn.recv(5000)
remote_conn.close()
Details output:
servera# scope org engg
Error: Managed object does not exist # org engg is not exist that the reason we are getting this error
servera#
servera# show service-profile
% Incomplete Command at '^' marker # since the above command is failed but paramiko does not able to identify it is moving to second command execution . There is no org engg so that the reason i am getting incomplete command warning.
Note: This is not a shell so I have to use shell invoke here.
Please help how to detect not successful ran command and terminate the python program.