fgimian / paramiko-expect

A Python expect-like extension for the Paramiko SSH library which also supports tailing logs.
MIT License
204 stars 78 forks source link

Long running commands are always failed with error message #57

Open k-jayaraman opened 4 years ago

k-jayaraman commented 4 years ago

I would like to execute some commands on the remote server . Usually that command took 1 hour to complete the task on the remote server .

But this module failed as below .

PROMPT = '.*\$\s+'

Used the above mentioned PROMPT value.

Traceback (most recent call last): File "/usr/local/lib/python3.7/site-packages/paramiko/channel.py", line 699, in recv out = self.in_buffer.read(nbytes, self.timeout) File "/usr/local/lib/python3.7/site-packages/paramiko/buffered_pipe.py", line 164, in read raise PipeTimeout() paramiko.buffered_pipe.PipeTimeout

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "code.py", line 71, in main interact.expect(PROMPT) File "/usr/local/lib/python3.7/site-packages/paramiko_expect.py", line 144, in expect current_buffer = self.channel.recv(self.buffer_size) File "/usr/local/lib/python3.7/site-packages/paramiko/channel.py", line 701, in recv raise socket.timeout() socket.timeout

Kindly let me know your comments on this issue

fruch commented 4 years ago

The default timeout is 60 seconds, use the timeout parameter to set it to something longer then your command

vinaykumar-c commented 4 years ago

@k-jayaraman @fruch If the timeout increase is not solving the problem then use the keepalive factor along with the timeout which is mentioned below.

            self._connection = SSHClientInteraction(self.client, timeout=<use_timeout_number>, display=True, buffer_size=2048)
            self._connection.channel.transport.set_keepalive(2)