Worth, Kevin
2008-Oct-28 16:51 UTC
[Net-ssh-users] Requesting shell channel using net-ssh2
A network device I''m trying to use net-ssh to script doesn''t
seem to support the "exec" call. When I tried to request a shell (I
pulled the example from the "send_channel_request" rdoc), I got the
message that I had to request a pty first. This led me to the below code, which
is mostly pulled from examples in the rdoc. This code logs into the device, and
appears to start a shell successfully, but it then loops forever because in my
"on_data" callback, I have a "send_data" call. Am I going
about this in any way that resembles correctness?
Would sure be nice if a full "shell" capability were available like in
1.x or else the examples contained enough information that making a shell-like
environment in which you have all the control you needed was easy. Something
like the two examples in http://net-ssh.rubyforge.org/ssh/v1/chapter-5.html#s2
would be really helpful.
-Kevin
require ''net/ssh''
Net::SSH.start(myhostname, myusername,
:password=>mypassword,:verbose=>:info) do |ssh|
ssh.open_channel do |channel|
channel.request_pty do |pty, success|
if success
puts "pty successfully obtained"
else
puts "could not obtain pty"
end
end
channel.send_channel_request "shell" do |sh, success|
if success
puts "user shell started successfully"
else
puts "could not start user shell"
end
end
channel.on_data do |ch, data|
puts "got stdout: #{data}"
channel.send_data "\n"
end
channel.on_extended_data do |ch, type, data|
puts "got stderr: #{data}"
end
channel.on_close do |ch|
puts "channel is closing!"
end
channel.send_data("\nhelp")
end
ssh.loop
end
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://rubyforge.org/pipermail/net-ssh-users/attachments/20081028/75112fcc/attachment-0001.html>