ville.mattila@stonesoft.com wrote:>>Each call to #exec is done in a separate "context" from the
others; this
>>means that the "pwd" invocation is done independently of the
"cd /var"
>>invocation. To make it pass, you''d need to do like you did for
the
>>first exec--combine both commands into a single exec.
>>
>
>
> Ok, I kind of guessed this. Is there any way to do keep the contex?
I''m
> hoping
> to get same kind of functionality as Telnet#cmd.
You can use the "Net::SSH::Service::Process.popen3" method to start a
synchronous "session" over a given connection. Something like this:
Net::SSH.start( host, login, password ) do |session|
input, output, error Net::SSH::Service::Process.popen3( session,
"sh" )
input.puts "cd /var"
input.puts "pwd"
result = output.read
input.puts "exit"
assert_equal "/var", result
end
It''s not as visually pleasing as Telnet#cmd, but it should work for
now.
The problem is that the SSH protocol is much more complicated than
Telnet, running multiple channels in parallel. However, given the popen3
functionality, it should be possible to further abstract that away to
get something closer to the Telnet#cmd interface.
Hope that helps,
Jamis
--
Jamis Buck
jgb3@email.byu.edu
http://www.jamisbuck.org/jamis
"I use octal until I get to 8, and then I switch to decimal."