Command to be send along with password in ruby 1.9.2 with netssh 2.1.4


Im stuck with command execution on remote computer.

I execute command on remote computer, but when i fire command it asks to
provide credentials too i.e password. Something like this :

[[email protected] ~]$ echo “sh cluster” | kashell
Credential expired, enter password for “kazeon”:

I written a code for it .
This code works properly in Ruby 1.8.7


Net::SSH.start(okMachine, user, passwd, :paranoid => false ) do

session.open_channel do |channel|

channel.on_success do
  puts "shell was started successfully!"

  puts "Adding command - #{command}..."

  channel.send_data "#{command}\n"

  channel.send_data "exit\n" # tell the shell to exit
channel.on_failure do
  puts "shell could not be started!"

channel.on_data do |ch,data|
  puts "recieved the following from shell"
  puts "#{data}"
  tempString = tempString + "\n" + data

channel.on_close do
  puts "shell terminated"

channel.send_request "shell", nil, true


But now with ruby 1.9.2 and netssh 2.1.4 same commands does not work
becasue there is no on_success method defined.

I written the code again like :

def issueCommandInKazBox6(okMachine="", command="", matchLog="",
user=“admin”, passwd=“kazeon”)
puts " issueCommandInKazMachine=#{okMachine}"
puts " issueCommandInKazcommand=#{command}"
puts " issueCommandInKazstatus=#{matchLog}"
puts " issueCommandInKazuser=#{user}"
puts " issueCommandInKazpasswd=#{passwd}"
#cms1 = “su admin”
#puts cms1

Net::SSH.start(okMachine, user, :password => “kazeon”) do |session|
puts “\t\t\tBAD”
puts command
session.open_channel do |ch|
puts “bhavesh”

    ch.send_data "#{command}\n"
    ch.send_data "exit\n"
    puts "sharma"
    puts "shell was started successfully!"

    puts "Adding command - #{command}..."

puts "after loop"
#ch.send_data "exit\n"

#ch.send_data “exit\n”

But nothig is working.

I m not getting how to send comand along with pasword so that command
gets executed and output of that command is being collected.

Do someone know about this ?


This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs