I have a code where i am executing a command on remote Linux machine and reading the output using Paramiko. The code def looks like this:
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect(IPAddress, username=user['username'], password=user['password'])
chan = self.ssh.get_transport().open_session()
chan.settimeout(10800)
try:
# Execute thecommand
chan.exec_command(cmd)
contents = StringIO.StringIO()
data = chan.recv(1024)
# Capturing data from chan buffer.
while data:
contents.write(data)
data = chan.recv(1024)
except socket.timeout:
raise socket.timeout
output = contents.getvalue()
return output,chan.recv_stderr(600),chan.recv_exit_status()
The above code works for small outputs, but it gets stuck for larger outputs.
Is there any buffer related issue in here?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…