0

Im using paramiko to execute python script on remote machine. I want paramiko to execute the script on the remote machine and continue without closing the script.

this my code now:

command = "python3 script.py"

client = paramiko.SSHClient() 
client.load_system_host_keys()
client.set_missing_host_key_policy(paramiko.AutoAddPolicy)
client.connect(ip,port,user,password)

stdin, stdout, stderr = self.client.exec_command(command)

while(True):
     "do something"

So right now the python script is starting and finishing really fast (altought it suppose to run for hour) and then "do something" happend. I want the script.py to finish on the remoth machine while "do something" happend. "Invoke the script and forget about it"

1 Answers1

1

That's what your code does. But if the command prints (lots of) output, once the output buffers fill, the script will hang and never finish.

If you are not interested in the output, an easy solution is to discard the it:

command = "python3 script.py > /dev/null 2>&1"
Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992