groovy-ssh icon indicating copy to clipboard operation
groovy-ssh copied to clipboard

What about an expect-like interaction support?

Open rzabini opened this issue 10 years ago • 1 comments

Hi, I have some use cases in which an expect-like syntax for interacting with the ssh server would be preferable. In this approach, you send commands and expect the server to answer with a pattern. I found this java implementation, and adapted it to the context of groovy-ssh; the result is in this branch of my forked repository. I did not alter any file of the original source, and put the new code in a different package, for the sake of readability.

This is a fragment of a unit test that explains the function:

ssh.run {
    session(ssh.remotes.testServer) {
        shellExpect {
            send 'hello server'
            expectOrThrow 1,'please enter password:'
            send 'Welcome1'
            expectOrThrow 1, 'password OK'
        }
    }
}

If you think this could be useful, I can define a pull request, removing the custom package name.

rzabini avatar Apr 12 '15 17:04 rzabini

Sounds good. Would you send me a pull request? Thanks

int128 avatar Apr 19 '15 14:04 int128