I have a long running program on my remote server, which I want to start with Paramiko.
I know how to start a program in the background (with nohup
for example) but my program first needs a few user inputs. In a normal SSH session I would pass those interactively over the terminal and then detach (Ctrl+Z, bg
, detach
) but I can't do this with Paramiko.
Here is what I've been trying so far:
stdin, stdout, stderr = ssh.exec_command('MyCommand', get_pty=True)
stdin.channel.send(b'MyData\r')
stdin.channel.send(b'\x1A') # This is Ctrl+Z
ssh.exec_command('bg; disown')
ssh.close()
but when the SSH connection closes, the remote program also stops running. How can I send user input to a program, that I want to continue running in the background?