Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SSH module for python

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 ?

like image 532
Jatin Kumar Avatar asked Jul 04 '11 09:07

Jatin Kumar


1 Answers

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()
like image 116
ars Avatar answered Oct 18 '22 22:10

ars