# Net:: SSH slowness issues

**URL:** <https://www.ruby-forum.com/t/net-ssh-slowness-issues/196655>\
**Category:** Rails\
**Created:** [April 26, 2008, 5:33am UTC](https://www.ruby-forum.com/t/net-ssh-slowness-issues/196655 "2008-04-26T05:33:50Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![bbazzarrakk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/47e85d/32.png) [@bbazzarrakk](https://www.ruby-forum.com/u/bbazzarrakk)\
**Post date:** [April 26, 2008, 5:33am UTC](https://www.ruby-forum.com/t/net-ssh-slowness-issues/196655/1 "2008-04-26T05:33:50Z")

</div>

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}"
  begin
    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"
        end

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

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

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

      channel.request_pty :want_reply => true
    end

  rescue Exception => myexp
    puts myexp
    $cmd_rslt = ""
  ensure
    $cmd_done = true
  end
end
```

---

<div class="post-metadata">

**Author:** ![bbazzarrakk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/47e85d/32.png) [@bbazzarrakk](https://www.ruby-forum.com/u/bbazzarrakk)\
**Post date:** [April 26, 2008, 6:50am UTC](https://www.ruby-forum.com/t/net-ssh-slowness-issues/196655/2 "2008-04-26T06:50:35Z")

</div>

James G. wrote:

> 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.  
> Almost sounds like a reverse DNS lookup problem on the Server. On  
> the target server, if you do a “nslookup x.x.x.x” with the IP address  
> of the client machine, does it return the host name right away?  
> If not, your connection is taking so long because sshd is timing  
> out on the reverse DNS lookup for the client’s IP address.

If this is the problem, then you need to either set up DNS on the  
server to know the reverse DNS for the IP address of the client, or  
perhaps change UseDNS no in /etc/ssh/sshd\_config.

As per keeping the connection Open, I’m not sure about net-ssh but  
you could use the OpenSSH command line to do port forwarding or  
a VPN that is always open…

Hope this helps,

–  
[http://myutil.com/](http://myutil.com/)

---

<div class="post-metadata">

**Author:** ![bbazzarrakk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/47e85d/32.png) [@bbazzarrakk](https://www.ruby-forum.com/u/bbazzarrakk)\
**Post date:** [April 26, 2008, 7:04am UTC](https://www.ruby-forum.com/t/net-ssh-slowness-issues/196655/3 "2008-04-26T07:04:02Z")

</div>

face wrote:

> If this is the problem, then you need to either set up DNS on the  
> server to know the reverse DNS for the IP address of the client, or  
> perhaps change UseDNS no in /etc/ssh/sshd\_config.
> 
> As per keeping the connection Open, I’m not sure about net-ssh but  
> you could use the OpenSSH command line to do port forwarding or  
> a VPN that is always open…
> 
> Hope this helps,

Oops I missed the part of the “CISCO BTS server”…so the server config  
might be a little different, but it still sounds like a Reverse DNS  
issue,  
so if you fix the DNS server that the Cisco is talking to, it should fix  
your  
problem (if that is what it is).

Thanks,  
-rm

---

<div class="post-metadata">

**Author:** ![bbazzarrakk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/47e85d/32.png) [@bbazzarrakk](https://www.ruby-forum.com/u/bbazzarrakk)\
**Post date:** [April 26, 2008, 7:06am UTC](https://www.ruby-forum.com/t/net-ssh-slowness-issues/196655/4 "2008-04-26T07:06:32Z")

</div>

When I do the whole process of ssh into the box and run the commands, it  
works much faster through the normal command line. Its when I try to run  
this via the ruby application. It takes time like close to 40 seconds.  
The target server box is a BTS switch and I dont think we have any  
access to do the dns part in there. But the funny thing is that it all  
works at a blazing speed when attempted through the normal command line  
interface.

---

<div class="post-metadata">

**Author:** ![bbazzarrakk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/47e85d/32.png) [@bbazzarrakk](https://www.ruby-forum.com/u/bbazzarrakk)\
**Post date:** [April 26, 2008, 8:09am UTC](https://www.ruby-forum.com/t/net-ssh-slowness-issues/196655/5 "2008-04-26T08:09:43Z")

</div>

James G. wrote:

> When I do the whole process of ssh into the box and run the commands, it  
> works much faster through the normal command line. Its when I try to run  
> this via the ruby application. It takes time like close to 40 seconds.  
> The target server box is a BTS switch and I dont think we have any  
> access to do the dns part in there. But the funny thing is that it all  
> works at a blazing speed when attempted through the normal command line  
> interface.

I tested your code on a standard sshd server and it was very fast  
(on net-ssh 1.1.2 and OpenSSH\_4.7).

But it seems like “SyncShell Service” might work for you original  
question about keeping the shell open:  
[http://net-ssh.rubyforge.org/chapter-5.html#s4](http://net-ssh.rubyforge.org/chapter-5.html#s4)

## Thanks, -rm

[http://myutil.com/](http://myutil.com/)
