[ Running Multiple SSH Commands Using Paramiko in Python 3.4.3 ]
I'm trying to run multiple commands on a box, but ONLY the first command succeeds. It seems something related to fork, but I cannot figure out how to resolve this. Your help or guidance will be deeply appreciated.
MY SCRIPT
import paramiko
#Made in python 3.4.3
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect('xxx.xx.xx.xx', port=22, username='domain\myusername', password='mypassword')
stdin, stdout, stderr = ssh.exec_command('vol status -f') #this being the first command works fine
output = stdout.readlines()
print ("\n".join(output))
stdin, stdout, stderr = ssh.exec_command('disk show -n')
output1 = stdout.readlines()
print ("\n".join(output1))
#stdin, stdout, stderr = ssh.exec_command('vol status -s')
#stdin, stdout, stderr = ssh.exec_command('df -Ag')
ssh.close()
input("Press <Enter> to exit ")
OUTPUT:
Traceback (most recent call last):
File "C:\Users\myusername\Desktop\folder_copy\test.py", line 13, in <module>
stdin, stdout, stderr = ssh.exec_command('disk show -n')
File "C:\Python34\lib\site-packages\paramiko-1.16.0-py3.4.egg\paramiko\client.py", line 401, in exec_command
chan = self._transport.open_session(timeout=timeout)
File "C:\Python34\lib\site-packages\paramiko-1.16.0-py3.4.egg\paramiko\transport.py", line 702, in open_session
timeout=timeout)
File "C:\Python34\lib\site-packages\paramiko-1.16.0-py3.4.egg\paramiko\transport.py", line 823, in open_channel
raise e
File "C:\Python34\lib\site-packages\paramiko-1.16.0-py3.4.egg\paramiko\transport.py", line 1726, in run
ptype, m = self.packetizer.read_message()
File "C:\Python34\lib\site-packages\paramiko-1.16.0-py3.4.egg\paramiko\packet.py", line 386, in read_message
header = self.read_all(self.__block_size_in, check_rekey=True)
File "C:\Python34\lib\site-packages\paramiko-1.16.0-py3.4.egg\paramiko\packet.py", line 251, in read_all
raise EOFError()
EOFError
Answer 1
If you believe fork is the issue, try the atfork()
method of the Transport class.