1

I am trying to use the Net::SSH library to login and manage a host that supports ssh. It is a piece of telecom equipment and so speaks TL1. I seem to be able to log in successfully, but when I try to ssh.exec something, it aborts saying it could not execute command. Here is my simple code:

require 'net/ssh'

Net::SSH.start('10.204.121.192', 'password', :password => "password") do |ssh|
  ssh.exec("INH-MSG-ALL;")
end

If i point the same code at a Linux server and provide a command such as "ls -l /", it works fine. What I am wondering is, can I use this ssh library? Do I need to use another command instead of exec?

This is the error output:

/usr/local/rvm/gems/ruby-1.9.2-p290/gems/net-ssh-2.2.1/lib/net/ssh/connection/session.rb:322:in `block (2 levels) in exec': could not execute command: "INH-MSG-ALL;" (RuntimeError)
from /usr/local/rvm/gems/ruby-1.9.2-p290/gems/net-ssh-2.2.1/lib/net/ssh/connection/channel.rb:597:in `call'
from /usr/local/rvm/gems/ruby-1.9.2-p290/gems/net-ssh-2.2.1/lib/net/ssh/connection/channel.rb:597:in `do_failure'
from /usr/local/rvm/gems/ruby-1.9.2-p290/gems/net-ssh-2.2.1/lib/net/ssh/connection/session.rb:586:in `channel_failure'
from /usr/local/rvm/gems/ruby-1.9.2-p290/gems/net-ssh-2.2.1/lib/net/ssh/connection/session.rb:456:in `dispatch_incoming_packets'
from /usr/local/rvm/gems/ruby-1.9.2-p290/gems/net-ssh-2.2.1/lib/net/ssh/connection/session.rb:213:in `preprocess'
from /usr/local/rvm/gems/ruby-1.9.2-p290/gems/net-ssh-2.2.1/lib/net/ssh/connection/session.rb:197:in `process'
from /usr/local/rvm/gems/ruby-1.9.2-p290/gems/net-ssh-2.2.1/lib/net/ssh/connection/session.rb:161:in `block in loop'
from /usr/local/rvm/gems/ruby-1.9.2-p290/gems/net-ssh-2.2.1/lib/net/ssh/connection/session.rb:161:in `loop'
from /usr/local/rvm/gems/ruby-1.9.2-p290/gems/net-ssh-2.2.1/lib/net/ssh/connection/session.rb:161:in `loop'
from /usr/local/rvm/gems/ruby-1.9.2-p290/gems/net-ssh-2.2.1/lib/net/ssh/connection/session.rb:110:in `close'
from /usr/local/rvm/gems/ruby-1.9.2-p290/gems/net-ssh-2.2.1/lib/net/ssh.rb:194:in `start'
from ssh_test.rb:3:in `<main>'

2 Answers 2

1

I assume it works fine when you login in the shell manually.

To understand what is the difference when you connect through net/ssh collect output of env command in both cases and compare.

That most probably you'll see a difference that will lead you to a solution or at least will give you dirty trick.

UPDATE. (Not working)

Net::SSH.start('10.204.121.192', 'password', :password => "password") do |ssh|
   ssh.open_channel do |channel|
        channel.on_data do |ch, data|
          puts "got data: #{data.inspect}"
        end
        channel.send_data("INH-MSG-ALL;\n")
   end
end

UPDATE2. (Working)

Net::SSH.start('10.204.121.192', 'password', :password => "password") do |ssh|
   ssh.open_channel do |channel|
        channel.send_channel_request "shell"
        channel.on_data do |ch, data|
          puts "got data: #{data.inspect}"
        end
        channel.send_data("INH-MSG-ALL;\n")
   end
end
Sign up to request clarification or add additional context in comments.

7 Comments

Okay, I am not quite sure what you mean the "env" command, in ruby? or on the host I am ssh'ed into? If the later, there is no env command on the device I ssh into as it only speaks TL1. I did try printing out the ENV has in ruby using pp to see if something there changes, and it does not.
There is another method send_data. Try it.
And don't forget \n in the end because most probably it is some binary that spawns on ssh connection so that you're actually speaking not to a shell but to some other binary in/out/err.
Hmm, there is only send_message for Net::SSH::Connection::Session and I tried this. It does not abort, but nothing seems to happen, I don't know how to read the output, if there is any. I did see send_data for a channel, so I tried this as well channel = ssh.open_channel do |ch| ch.send_data("INH-MSG-ALL;\n") end but this just hangs
hmm, this also hangs, this is my code: channel = ssh.open_channel do |ch| channel.on_data do |ch, data| puts "got data: #{data.inspect}" end channel.send_data("INH-MSG-ALL;\n") end
|
0

Thanks forker for your updates),

One more thing,

from your code how to make this

puts "got data: #{data.inspect}"

to output data for each command sent to the shell ?

Does this code wait for each command to complete?

Thanks.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.