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

Handling interactive command #1

Open
KINGSABRI opened this issue Jul 12, 2019 · 3 comments
Open

Handling interactive command #1

KINGSABRI opened this issue Jul 12, 2019 · 3 comments

Comments

@KINGSABRI
Copy link

Hi
I'm writing a simple ssh client, the gem is working well and stable for me. However, I'm facing an issue (the script hangs) when I deal with interactive commands such as passwd.

Is there an easy way to handle this situation?

@stillhart
Copy link
Collaborator

Try the dialog method. It would be something like this for your passwd example:

cli.dialog "passwd", /Current Password:/i
cli.dialog "Old Password", /New Password:/i
cli.dialog "New Password", /Repeat Password:/i
cli.cmd "New Password"

you also could specify the prompt as an option of cmd

cli.cmd "passwd", prompt: /Current Password:/i

You also could just go the fire and forget way, but you would have way less guarantees:

cli.cmd "passwd\nOld Password\nNew Password\nNew Password"

But like this, you have a higher risk of it hanging somewhere.

If you have a look at the source code, you can see that most methods are just ways around this

cli.write "passwd\n"
cli.stdout
# => current buffer state
cli.process
# further 'process' packets of the SSH connection => fills/empties the buffer

@KINGSABRI
Copy link
Author

I see,

The dialg way is elegant to me. However, It would be great to have something to expect any dialog prompt in general by default.

I don't know if there is a specific STDOUT behavior for the interactive dialogs or not.

I understand the gem is made for expected output scripting and in my case I want to make it general case.

@KINGSABRI
Copy link
Author

I think the best example for interactive behavior is opening a file using a text editor like nano/vim.

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

No branches or pull requests

2 participants