# Net-ssh and remote shell

**URL:** <https://www.ruby-forum.com/t/net-ssh-and-remote-shell/144244>\
**Category:** Ruby\
**Created:** [July 27, 2008, 11:30am UTC](https://www.ruby-forum.com/t/net-ssh-and-remote-shell/144244 "2008-07-27T11:30:54Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Une\_BSSSSvS\_ue](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/2acd7d/32.png) [@Une\_BSSSSvS\_ue](https://www.ruby-forum.com/u/Une_BSSSSvS_ue)\
**Post date:** [July 27, 2008, 11:30am UTC](https://www.ruby-forum.com/t/net-ssh-and-remote-shell/144244/1 "2008-07-27T11:30:54Z")

</div>

following the page :  
[http://drnicwilliams.com/2006/09/22/remote-shell-with-ruby/](http://drnicwilliams.com/2006/09/22/remote-shell-with-ruby/)

i’ve uninstalled net-ssh and the like then,  
intall needle-1.3.0.gem  
and re-installed :  
net-ssh-2.0.3.gem  
net-scp-1.0.1.gem  
net-ssh-gateway-1.0.0.gem  
net-ssh-multi-1.0.0.gem

## after that, i wanted to test a small piece of code :

#! /usr/bin/env ruby

require ‘rubygems’  
require ‘needle’  
require ‘net/ssh’  
require ‘lib/preferences’ # gives the options  
require ‘lib/tt\_check’ # gives tt\_connected? (verify the USB-lan is  
connected)

## if tt\_connected? result=“” session=Net::SSH.start(“TT”, “root”, options) shell=session.shell.sync ### \<\<\<=== line 13 out=shell.send\_command ‘ls -lart’ puts out.stdout else puts “Twin-Tact is not connected.” end

and i got :  
$ ./ssh\_shell\_sync.rb  
./ssh\_shell\_sync.rb:13: undefined method `shell’ for  
#Net::SSH::Connection::Session:0x16b4fd0 (NoMethodError

then, i wonder if there is a special way to install net-ssh to let it  
take into account “Needle” ???

---

<div class="post-metadata">

**Author:** ![Une\_BSSSSvS\_ue](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/2acd7d/32.png) [@Une\_BSSSSvS\_ue](https://www.ruby-forum.com/u/Une_BSSSSvS_ue)\
**Post date:** [July 28, 2008, 10:45am UTC](https://www.ruby-forum.com/t/net-ssh-and-remote-shell/144244/2 "2008-07-28T10:45:33Z")

</div>

Your code example works with net-shh 1.1.2 but not 2.0.3

For this sort of thing I prefer to use the .exec method and store all  
output in an array:

require ‘rubygems’  
require ‘needle’  
require ‘net/ssh’  
session=Net::SSH.start(“localhost”,  
“90kts”, :password=\>"\*\*\*\*\*\*\*\*\*\*\*\*\*\*")  
cmd = ‘ls -lart’  
out = []  
out = session.exec!(cmd).split(/\n/)  
puts out

Hope that helps =)

---

<div class="post-metadata">

**Author:** ![Une\_BSSSSvS\_ue](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/2acd7d/32.png) [@Une\_BSSSSvS\_ue](https://www.ruby-forum.com/u/Une_BSSSSvS_ue)\
**Post date:** [July 28, 2008, 12:01pm UTC](https://www.ruby-forum.com/t/net-ssh-and-remote-shell/144244/3 "2008-07-28T12:01:02Z")

</div>

90kts [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> out = session.exec!(cmd).split(/\n/)  
> puts out
> 
> Hope that helps =)

yes fine !

what is the usefullness of “needle” here ?

I’ve installed it, but don’t know how to verify net/ssh makes use of  
it…

also, I’m unable to have a command with “cd /some/path”

cd is a built-in, i think that’s the prob.

---

<div class="post-metadata">

**Author:** ![Une\_BSSSSvS\_ue](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/2acd7d/32.png) [@Une\_BSSSSvS\_ue](https://www.ruby-forum.com/u/Une_BSSSSvS_ue)\
**Post date:** [July 28, 2008, 12:10pm UTC](https://www.ruby-forum.com/t/net-ssh-and-remote-shell/144244/4 "2008-07-28T12:10:24Z")

</div>

Une Bévue [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> also, I’m unable to have a command with “cd /some/path”
> 
> cd is a built-in, i think that’s the prob.

for example, with :  
session.exec!(“cd /mnt/fat;ls -Al”)

i get :  
exec: 4: cd: not found

???

---

<div class="post-metadata">

**Author:** ![Une\_BSSSSvS\_ue](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/2acd7d/32.png) [@Une\_BSSSSvS\_ue](https://www.ruby-forum.com/u/Une_BSSSSvS_ue)\
**Post date:** [July 28, 2008, 1:20pm UTC](https://www.ruby-forum.com/t/net-ssh-and-remote-shell/144244/5 "2008-07-28T13:20:47Z")

</div>

On Jul 28, 8:06 pm, [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) (Une  
Bévue) wrote:

> ## ???
> 
> Une Bévue

needle is a dependency, it will complain if you try and install net-  
ssh without it.  
for your example, just do this:  
session.exec!(“ls -Al /mnt/fat”)

---

<div class="post-metadata">

**Author:** ![Une\_BSSSSvS\_ue](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/2acd7d/32.png) [@Une\_BSSSSvS\_ue](https://www.ruby-forum.com/u/Une_BSSSSvS_ue)\
**Post date:** [July 28, 2008, 1:39pm UTC](https://www.ruby-forum.com/t/net-ssh-and-remote-shell/144244/6 "2008-07-28T13:39:35Z")

</div>

On Mon Jul 28 19:09:39 2008, Une\_B=E9vue wrote:

> exec: 4: cd: not found
> 
> ## ???
> 
> Une BÃ©vue

You will need to use Dir#chdir to change directories.

---

<div class="post-metadata">

**Author:** ![Une\_BSSSSvS\_ue](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/2acd7d/32.png) [@Une\_BSSSSvS\_ue](https://www.ruby-forum.com/u/Une_BSSSSvS_ue)\
**Post date:** [July 28, 2008, 3:41pm UTC](https://www.ruby-forum.com/t/net-ssh-and-remote-shell/144244/7 "2008-07-28T15:41:36Z")

</div>

90kts [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> needle is a dependency, it will complain if you try and install net-  
> ssh without it.

not sure about that point because i did two installs the first without  
needle, i’ve uninstalled afterwards, install needle, and re-install  
net/ssh.  
no visible differences ???

> for your example, just do this:  
> session.exec!(“ls -Al /mnt/fat”)

yes, of course, it was only an example.

---

<div class="post-metadata">

**Author:** ![Une\_BSSSSvS\_ue](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/2acd7d/32.png) [@Une\_BSSSSvS\_ue](https://www.ruby-forum.com/u/Une_BSSSSvS_ue)\
**Post date:** [July 29, 2008, 2:00am UTC](https://www.ruby-forum.com/t/net-ssh-and-remote-shell/144244/8 "2008-07-29T02:00:46Z")

</div>

On Jul 28, 11:36 pm, [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) (Une  
Bévue) wrote:

> > for your example, just do this:  
> > session.exec!(“ls -Al /mnt/fat”)
> 
> ## yes, of course, it was only an example.
> 
> Une Bévue

Does it not automatically install dependencies by default?

When I install from a local gem (no connection to internet) it will  
complain that it doesn’t have the required dependency (needle)

Try installing with --ignore-dependencies and see what happens…  
Anyhoo ..

---

<div class="post-metadata">

**Author:** ![Une\_BSSSSvS\_ue](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/2acd7d/32.png) [@Une\_BSSSSvS\_ue](https://www.ruby-forum.com/u/Une_BSSSSvS_ue)\
**Post date:** [July 29, 2008, 2:46pm UTC](https://www.ruby-forum.com/t/net-ssh-and-remote-shell/144244/9 "2008-07-29T14:46:36Z")

</div>

90kts [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Does it not automatically install dependencies by default?
> 
> When I install from a local gem (no connection to internet) it will  
> complain that it doesn’t have the required dependency (needle)

Quiest frankly i don’t remember that point…  
If i remember well i’ve installed net/ssh from local gems without needle  
the first time.
