[rspec-users] Net:SSH

James George lists at ruby-forum.com
Fri Apr 25 04:59:24 EDT 2008

Guys I'm having a problem with net-ssh, its kinda taking too long to
execute a command and give me the results. It takes around 40 seonds to
do it. And  I have 3-4 commands to run on the remote box. Is there any
possibility to speed up the process. Im using the commands to run on a
CISCO BTS server. Is there any possibility that I cud keep  channel or
session open as long s i could and get the results. Each command I run
depends on the result of the previous one I run. Since we have to send
the exit command to get the ondata, its not helping much in speeding the
whole process. Can anyone help me out there to speed this whole porcess.

Thanks GUys, heres the code below :

    def execute_cmd(ssh_ssn, cmd_string)
      $cmd_rslt = ""
      $cmd_done = false
      puts "executing command: #{cmd_string} in session #{ssh_ssn}"
        ssh_ssn.open_channel do |channel|

          channel.on_success do
            puts "pty requested successfully!"

            channel.on_success do
              puts "shell started successfully!"
              channel.send_data cmd_string + "\n"
              channel.send_data "exit\n"

            channel.on_data do |ch,data|
              #puts "rcvd #{data}"
              $cmd_rslt << data
            channel.send_request "shell", nil, true

          channel.on_failure do
            puts "shell could not be started!"

          channel.on_close do
            puts "shell terminated"
            $cmd_done = true

          channel.request_pty :want_reply => true

      rescue Exception => myexp
        puts myexp
        $cmd_rslt = ""
        $cmd_done = true
Posted via http://www.ruby-forum.com/.

More information about the rspec-users mailing list