I am having some trouble with Paramiko module while running a command on remote server.
def check_linux(cmd, client_ip, client_name):
port = 22
usern
The .read
will wait until the command finishes, what it never does.
Instead, wait for the command to finish first. If it is taking too long, kill the command (using stdout.channel.close()
).
You can use the code from Python Paramiko exec_command timeout doesn't work?:
timeout = 30
import time
endtime = time.time() + timeout
while not stdout.channel.eof_received:
time.sleep(1)
if time.time() > endtime:
stdout.channel.close()
break
status = stdout.read()
Though you can use the above code, only if the command produces very little output. Otherwise the code might deadlock. For a robust solution, you need to read the output continuously.
See A command does not finish when executed using Python Paramiko exec_command