Ok so I've managed to get this working using SSHClient.invoke_shell(), and monitoring it's output. Solaris hardware all come with ILOM (Integrated Lights Out Manager) configured, which is very useful getting a serial console on a machine.
client = paramiko.SSHClient()
client.load_system_host_keys()
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
client.connect("9.9.9.9", 22, "username", "password")
channel = client.invoke_shell()
channel.settimeout(0.0)
while True:
r, w, e = select.select([channel], [], [])
try:
console_data = ""
while channel.recv_ready():
console_data += channel.recv(1024)
if len(console_data) == 0:
print "\n*** EOF\n"
break
# Search console_data for console prompt
# If found, start a serial console
if re.search("->", console_data):
channel.send("start -script SP/Console")
elif re.search("y/n", console_data):
channel.send("y\n")
elif re.search("SOME STRING ON CONSOLE", console_data):
print "Action completed"
break
except socket.timeout:
pass
channel.close()
client.close()
Above code connects to Service port on ILOM and waits for "->" prompt, once received it starts the serial console via "start -script SP/Console", and then anwsers "y" to continue prompt.
Now we have serial console and can monitor all output to this serial console, when some predefined string is output to the console I can exit.