SSH module for python

喜欢而已 提交于 2019-11-29 10:03:36

问题


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 ?


回答1:


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()


来源:https://stackoverflow.com/questions/6569833/ssh-module-for-python

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!