[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Net::SSH problems

Bob Smyph

6/6/2008 11:34:00 AM

I am trying to connect to one of our UNIX servers. I can connect and can
validate myself but I cant seem to figure out how to 'cd' to another
directory besides my '/home' directory and then execute commands from
the new directory.

below is what I have so far and each time I execute this I receive the
below error
-----ERROR------
C:/ruby/test/SSHtest.rb:75: undefined method `shell' for
#<Net::SSH::Connection::Session:0x2e5bf30> (NoMethodError)
from c:/ruby/lib/ruby/site_ruby/1.8/net/ssh.rb:189:in `start'
from C:/ruby/test/SSHtest.rb:72
-----CODE-----
Net::SSH.start( "hostname", "username", :password => "Password" ) do
|session|
shell = session.shell.open
# script what we want to do
shell.pwd
shell.cd "/"
shell.pwd
shell.test "-e foo"
shell.cd "/file/trying/to/cd/to"
shell.send_data "program\n"
shell.pwd
shell.exit
# give the above commands sufficient time to terminate
sleep 0.5
# display the output
$stdout.print shell.stdout while shell.stdout?
$stderr.puts "-- stderr: --"
$stderr.print shell.stderr while shell.stderr?

end

-----

- I would greatly appreciate any help.
--
Posted via http://www.ruby-....

6 Answers

stephen O'D

6/6/2008 3:59:00 PM

0

On Jun 6, 12:33 pm, Bob Smyph <bobsm...@hotmail.com> wrote:
> I am trying to connect to one of our UNIX servers. I can connect and can
> validate myself but I cant seem to figure out how to 'cd' to another
> directory besides my '/home' directory and then execute commands from
> the new directory.
>
> below is what I have so far and each time I execute this I receive the
> below error
> -----ERROR------
> C:/ruby/test/SSHtest.rb:75: undefined method `shell' for
> #<Net::SSH::Connection::Session:0x2e5bf30> (NoMethodError)
> from c:/ruby/lib/ruby/site_ruby/1.8/net/ssh.rb:189:in `start'
> from C:/ruby/test/SSHtest.rb:72
> -----CODE-----
> Net::SSH.start( "hostname", "username", :password => "Password" ) do
> |session|
> shell = session.shell.open
> # script what we want to do
> shell.pwd
> shell.cd "/"
> shell.pwd
> shell.test "-e foo"
> shell.cd "/file/trying/to/cd/to"
> shell.send_data "program\n"
> shell.pwd
> shell.exit
> # give the above commands sufficient time to terminate
> sleep 0.5
> # display the output
> $stdout.print shell.stdout while shell.stdout?
> $stderr.puts "-- stderr: --"
> $stderr.print shell.stderr while shell.stderr?
>
> end
>
> -----
>
> - I would greatly appreciate any help.
> --
> Posted viahttp://www.ruby-....

Not sure what is wrong - I do something similar (this is snipped from
a bigger application, so it may not be the most idiomatic way to do
this, but it seems to work):

Net::SSH.start( CONFIG['target_machine'], CONFIG['user'],
CONFIG['password'] ) do |session|
shell = session.shell.sync
shell.send_command 'y' # To answer the 'are you allow to
authorize this computer questions

commands = [
"cd #{remote_dir}",
"chmod 777 somescript.ksh",
"./somescript.ksh"
]

commands.each do |c|
out = shell.send_command c
end
end

I know the 'build an array of commands' is silly here, but as I said
its part of a bigger app - it does the 'cd', 'chmod' and runs the
script with no issues however.

Bob Smyph

6/9/2008 12:15:00 PM

0

stephen O'D wrote:
> On Jun 6, 12:33 pm, Bob Smyph <bobsm...@hotmail.com> wrote:
>> from c:/ruby/lib/ruby/site_ruby/1.8/net/ssh.rb:189:in `start'
>> shell.cd "/file/trying/to/cd/to"
>> end
>>
>> -----
>>
>> - I would greatly appreciate any help.
>> --
>> Posted viahttp://www.ruby-....
>
> Not sure what is wrong - I do something similar (this is snipped from
> a bigger application, so it may not be the most idiomatic way to do
> this, but it seems to work):
>
> Net::SSH.start( CONFIG['target_machine'], CONFIG['user'],
> CONFIG['password'] ) do |session|
> shell = session.shell.sync
> shell.send_command 'y' # To answer the 'are you allow to
> authorize this computer questions
>
> commands = [
> "cd #{remote_dir}",
> "chmod 777 somescript.ksh",
> "./somescript.ksh"
> ]
>
> commands.each do |c|
> out = shell.send_command c
> end
> end
>
> I know the 'build an array of commands' is silly here, but as I said
> its part of a bigger app - it does the 'cd', 'chmod' and runs the
> script with no issues however.

I tried the above and I still get the same error.

#<Net::SSH::Connection::Session:0x2e5bf30> (NoMethodError)
from c:/ruby/lib/ruby/site_ruby/1.8/net/ssh.rb:189:in `start'
from C:/ruby/test/SSHtest.rb:95

Any more ideas?

--
Posted via http://www.ruby-....

Luis Lavena

6/9/2008 7:13:00 PM

0

On Jun 9, 2:14 pm, Bob Smyph <eric.ram...@cbc-companies.com> wrote:
> stephen O'D wrote:
> > On Jun 6, 12:33 pm, Bob Smyph <bobsm...@hotmail.com> wrote:
> >>         from c:/ruby/lib/ruby/site_ruby/1.8/net/ssh.rb:189:in `start'
> >>   shell.cd "/file/trying/to/cd/to"
> >> end
>
> >> -----
>
> >>  - I would greatly appreciate any help.
> >> --
> >> Posted viahttp://www.ruby-....
>
> > Not sure what is wrong - I do something similar (this is snipped from
> > a bigger application, so it may not be the most idiomatic way to do
> > this, but it seems to work):
>
> > Net::SSH.start( CONFIG['target_machine'], CONFIG['user'],
> > CONFIG['password'] ) do |session|
> >       shell = session.shell.sync
> >       shell.send_command 'y' # To answer the 'are you allow to
> > authorize this computer questions
>
> >       commands = [
> >         "cd #{remote_dir}",
> >         "chmod 777 somescript.ksh",
> >         "./somescript.ksh"
> >         ]
>
> >       commands.each do |c|
> >         out = shell.send_command c
> >       end
> > end
>
> > I know the 'build an array of commands' is silly here, but as I said
> > its part of a bigger app - it does the 'cd', 'chmod' and runs the
> > script with no issues however.
>
> I tried the above and I still get the same error.
>
> #<Net::SSH::Connection::Session:0x2e5bf30> (NoMethodError)
>         from c:/ruby/lib/ruby/site_ruby/1.8/net/ssh.rb:189:in `start'
>         from C:/ruby/test/SSHtest.rb:95
>
> Any more ideas?
>

What version of Ruby are you using?

In the first same looks like you're using ruby builtin Net::SSH
support, but dunno if shell is being part of a Session instance.

On the second example, looks like it even worse, but looking at the
line numbers (95!) seems you have a huge script.

Can you reproduce the problem in a small one and pastie it to us so we
can trace it? (try providing the full backtrace to ease the task).

Thanks,
--
Luis Lavena

Bob Smyph

6/9/2008 7:57:00 PM

0

Luis Lavena wrote:
> On Jun 9, 2:14�pm, Bob Smyph <eric.ram...@cbc-companies.com> wrote:
>> >> Posted viahttp://www.ruby-....
>>
>>
>> Any more ideas?
>>
>
> What version of Ruby are you using?

when looking under C:\ruby\doc\ruby it shows ruby-1.8.5

>
> In the first same looks like you're using ruby builtin Net::SSH
> support, but dunno if shell is being part of a Session instance.
>
> On the second example, looks like it even worse, but looking at the
> line numbers (95!) seems you have a huge script.

it is line 95 because I have lines 3-70 commented out so what is showing
in the first post is all that is being run and line 1 is require
'net/ssh'

>
> Can you reproduce the problem in a small one and pastie it to us so we
> can trace it? (try providing the full backtrace to ease the task).
>
> Thanks,

--
Posted via http://www.ruby-....

iarwain

8/16/2010 12:30:00 PM

0

> Mumbo sounds nothimg like the Bee Gees.

I see what you did there.

richforman

8/16/2010 2:33:00 PM

0

On Aug 15, 3:58 pm, lonelysum...@webtv.net (Ron Fowler) wrote:

> Mumbo is gibberish

Kind of stating the obvious there, Ron :) . But it does rock. I like
the fact that it is kind of like a bootleg of a work in progress -
makes me imagine that lots of Paul's rockers start out as gibberish
similar to this and then he fills them in with real words, in this
case he just decided to not even bother with that step. I like it
though, it's a throat-shredding vocal and the band rocks.

richforman