Edit: Using the snippet below I come across a few issues
import paramiko, threading
ssh=paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
def connectAndCMD(command):
ssh.connect('127.0.0.1',22,'MY_USER','MY_SSH_PASS')
stdin, stdout, stderr = ssh.exec_command(command)
print stdout.read()
commandList=[
"pwd",
"whoami",
"ls",
"echo hello",
"ping google.com",
"ifconfig | grep Bcast | awk {'print $2'}"
]
for command in commandList:
print '[',command, '] command thread started'
t=threading.Thread(target=connectAndCMD,args=(command,))
t.start()
In the console I see: SSHException: No existing session Oddly enough, when I reduce the size of the list to just a few commands, reducing thread count, I am able to see the output of one of the ssh commands of a random thread but then the script hangs indefinitely. What is the problem and how do I go about rectifying this?
This is a mockup but in my actual program I have threads being made to run the same command with just different parameters/options