I have to do a job (using my web server) on a remote machine that takes about 10 minutes.
I have used pxssh module in python for the same but it gives me "timeout error"(non blocking).
Now, I am using paramiko but that comes back as soon as it gives the instruction.
I want the web server to wait till the job is complete. Is there any python SSH module available for this.
Or
Can we achieve the same by changing any configuration settings of pxssh
or paramiko
?
You can use the recv_exit_status
method on the Channel to wait for the command to complete:
recv_exit_status(self)
Return the exit status from the process on the server. This is mostly useful for retrieving the reults of an exec_command. If the command hasn't finished yet, this method will wait until it does, or until the channel is closed. If no exit status is provided by the server, -1 is returned.
For example:
ssh = paramiko.SSHClient()
ssh.connect(remote, username=username, password=password)
ssh_stdin, ssh_stdout, ssh_stderr = ssh.exec_command("some command")
exit_status = ssh_stdout.channel.recv_exit_status()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With