So it doesn’t seem to work.
It works using more channels like this …
import paramiko
import cmd
import time
import sys
buff = ''
resp = ''
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect('192.168.99.10', username='test', password='test')
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
#run command
chan = ssh.invoke_shell()
# turn off paging
chan.send('terminal length 0\n')
time.sleep(1)
resp = chan.recv(9999) # recv(nbytes)
#Receive data from the channel. The return value is a string representing the data received.
# The maximum amount of data to be received at once is specified by nbytes.
# If a string of length zero is returned, the channel stream has closed.
output = resp.decode('ascii').split(',')
print (''.join(output))
# Display output of first command
chan.send('sh ip int br')
chan.send('\n')
time.sleep(1)
resp = chan.recv(9999)
output = resp.decode('ascii').split(',')
print (''.join(output))
# Display output of second command
chan.send('sh ver')
chan.send('\n')
time.sleep(1)
resp = chan.recv(9999)
output = resp.decode('ascii').split(',')
print (''.join(output))
#closer
ssh.close()
https://evilttl.com/wiki/Execute-MULTIPLE-commands-with-Python