Daedalus Mythos
Daedalus Mythos

Reputation: 575

How to wait for a process that has been started on a remote computer using ssh in a script?

I have a script that, in a specific case is required to run a very time-consuming script on a remote computer. I currently do this with:

if specific_case:
    client = paramiko.SSHClient()
    client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
    client.connect('10.0.0.1', username='username', password='password')
    stdin, stdout, stderr = client.exec_command('tmux new-session -d -s session_name \'python /home/username/flamethrower.py'\'')

Now - so far so good.. How could I wait for python /home/username/flamethrower.py in the script that initially started it and possibly have a minimalistic feedback?

The computer running the script that starts flamethrower.py on the remote computer is a windows 8.1, the computer where flamethrower.py is run, is a Debian wheezy.

pseudo coded:

[...] # as above
while not stdin, stdout, stderr = client.exec_command('tmux new-session -d -s session_name \'python /home/username/flamethrower.py'\''):

    #while it's not done, print a dot every minute
    sys.stdout.print('.')
    sys.flush()
    sleep(60)

Upvotes: 0

Views: 169

Answers (1)

Steve Barnes
Steve Barnes

Reputation: 28405

Have your remote script output to some log file, including when finished, then poll the remote connection every so often for the finish output, (and fetch the remaining output).

Upvotes: 2

Related Questions