paramiko-expect timeout is happening after executing the command
paramiko-expect timeout is happening after executing the command
Can someone help me why timeout is happening after executing the command .I am trying to SSH to a machine and execute a command.I want to store the result of the executed command . I have referred paramiko-timeout but i didn't get my expected result.
import traceback
try:
import paramiko
except ImportError:
raise Exception("Please install paramiko , pip install paramiko")
import pexpect
from paramiko_expect import SSHClientInteraction
def main():
HOSTNAME = "minion5.net"
USERNAME = "root"
PASSWORD = "help@432"
PROMPT = "root@*:~$s+"
try:
client = paramiko.SSHClient()
client.load_system_host_keys()
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
client.connect(hostname=HOSTNAME, username=USERNAME, password=PASSWORD)
with SSHClientInteraction(client, timeout=20, display=True) as interact:
interact.expect(PROMPT)
interact.send('hostname -f')
interact.expect(PROMPT)
interact.send('exit')
cmd_output = interact.current_output_clean
print cmd_output
except Exception:
traceback.print_exc()
finally:
try:
client.close()
except:
pass
if __name__ == '__main__':
main()
following is the output
[root@btpvm0740 paramiko-tests]# python sa-test.py
Last login: Thu Jun 14 11:13:10 2018 from btpvm0740.net
[root@minion5 ~]# Traceback (most recent call last):
File "sa-test.py", line 25, in main
interact.expect(PROMPT)
File "/usr/lib/python2.7/site-packages/paramiko_expect.py", line 144, in expect
current_buffer = self.channel.recv(self.buffer_size)
File "/usr/lib/python2.7/site-packages/paramiko/channel.py", line 685, in recv
raise socket.timeout()
timeout
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
Comments
Post a Comment