Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

channel.recv() problem #38

Open
draganmarkovic opened this issue Nov 17, 2017 · 7 comments
Open

channel.recv() problem #38

draganmarkovic opened this issue Nov 17, 2017 · 7 comments
Labels

Comments

@draganmarkovic
Copy link

Hi,

I've experienced issue when trying to match against output when running .expect() right after .send(). Expect does not show output as with pexpect library. It return the command I've sent along with prompts instead of returning result of the command.
If I introduce certain delay after each .send() it tends to work more correctly.

Thanks, Dragan

@marcelosz
Copy link

Same issue here!

@fruch
Copy link
Collaborator

fruch commented Dec 3, 2017

can you guy share an example ?

@mistergates
Copy link

mistergates commented Jul 20, 2018

timeout = 30
display = False
cmd = passwd
password = mynewpassword
exp_dict = {
                "New password: ":"{}".format(password), 
                "Retype new password: ":"{}".format(password), 
                "passwd: all authentication tokens updated successfully.":"\n"
            }
prompts = []
try:
    for prompt in exp_dict:
        prompts.append(prompt)
except Exception:
    print('Error building prompts list from exp_dict!')
    return '!! Failed !!'

try:
    # Create a new SSH client object
    client = paramiko.SSHClient()

    # Set SSH key parameters to auto accept unknown hosts
    client.load_system_host_keys()
    client.set_missing_host_key_policy(paramiko.AutoAddPolicy())

    # Connect to the host
    client.connect(hostname=server, username=myusername, password=mypassword)

    # Create a client interaction class which will interact with the host
    with SSHClientInteraction(client, timeout=timeout, display=display) as interact:           
        interact.send(cmd)
        for prompt in prompts:
            interact.expect(prompts) #expect a prompt for our prompts list
            interact.send(exp_dict[interact.last_match]) #send the value assinged to prompt key
        interact.send('exit')
        interact.expect()
        status = 'Success'
except Exception:
    status = '!! Failed !!'
    pass
finally:
    try:
        client.close()
    except:
        pass

return status

I am experiencing this same problem. Sometimes it returns success, sometimes it returns failure. If I add a 'time.sleep(.2)' after .send(), it seems to return success more often but still not 100%.

@msln1314
Copy link

Same issue here!,the not set time.sleep(2),after send,the expect get erro output, especically same time the output out of order after loop send command and expect

@gurucp
Copy link

gurucp commented Aug 25, 2018

I am also having the same issue ..

@fruch fruch added the question label Jul 24, 2019
@sureshkotapydev
Copy link

Facing similar issue. In my case, first partial output coming in self.current_output_clean and then this issue occurs for successive commands.

@a11apurva
Copy link

Any workarounds or fix yet?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

8 participants