[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

Usin net/ssh library

Prasad Pednekar

6/1/2008 9:23:00 AM


Hi,
I was using the net/ssh library in my code ro ssh to a particular
machine.
But I found that the ssh library goes directly to the shell prompt and
executes the commands. net/ssh uses the ssh2 protocol internally, I also
tried using ssh1
but with no success.

Initially the prompt that appears should have been something like ">>>>"
but
in my case after running the script it goes directly to the shell prompt
"$" by-passing the cli prompt.

a. Why does this behaviour take place??

b. Is there a way to go to the initial cli prompt ??


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

4 Answers

Phlip

6/1/2008 1:44:00 PM

0

> I was using the net/ssh library in my code ro ssh to a particular
> machine.
> But I found that the ssh library goes directly to the shell prompt and
> executes the commands. net/ssh uses the ssh2 protocol internally, I also
> tried using ssh1
> but with no success.
>
> Initially the prompt that appears should have been something like ">>>>"
> but
> in my case after running the script it goes directly to the shell prompt
> "$" by-passing the cli prompt.
>
> a. Why does this behaviour take place??
>
> b. Is there a way to go to the initial cli prompt ??

How does Capistrano do it?

John Maclean

6/2/2008 11:11:00 AM

0

On Sun, 1 Jun 2008 18:23:25 +0900
Prasad Pednekar <prasadp@gslab.com> wrote:

>=20
> Hi,
> I was using the net/ssh library in my code ro ssh to a particular
> machine.
> But I found that the ssh library goes directly to the shell prompt and
> executes the commands. net/ssh uses the ssh2 protocol internally, I also
> tried using ssh1
> but with no success.
>=20
> Initially the prompt that appears should have been something like ">>>>"
> but
> in my case after running the script it goes directly to the shell prompt
> "$" by-passing the cli prompt.
>=20
> a. Why does this behaviour take place??
>=20
> b. Is there a way to go to the initial cli prompt ??
>=20
>=20
> -P

=46rom `ri Net::SSH`

Net::SSH.start("host", "user", :password =3D> "password") do |ssh|
result =3D ssh.exec!("ls -l")
puts result
end


Sample of my own stuff...
require 'rubygems'
require 'net/ssh'

server =3D "acid"
user =3D "jayeola"
Net::SSH.start(server, user) do |x|
cmd2 =3D x.exec!("test -d /proc && echo \"OK\"").strip
p cmd2
if cmd2 !=3D "OK"
p "no proc found"
else
p "got proc"
end
=20
cmd3 =3D x.exec!("test -f /proc/partitions && echo \"OK\"")
cmd4 =3D x.exec!("test -f /proc/diskstats && echo \"OK\"") =20
end


I'm using this library and it doesn't give me a prompt at all but runs
the code as required. How are you using it?

Prasad Pednekar

6/2/2008 12:11:00 PM

0

John Maclean wrote:
> On Sun, 1 Jun 2008 18:23:25 +0900
> Prasad Pednekar <prasadp@gslab.com> wrote:
>
>> but
>> in my case after running the script it goes directly to the shell prompt
>> "$" by-passing the cli prompt.
>>
>> a. Why does this behaviour take place??
>>
>> b. Is there a way to go to the initial cli prompt ??
>>
>>
>> -P
>
> From `ri Net::SSH`
>
> Net::SSH.start("host", "user", :password => "password") do |ssh|
> result = ssh.exec!("ls -l")
> puts result
> end
>
>
> Sample of my own stuff...
> require 'rubygems'
> require 'net/ssh'
>
> server = "acid"
> user = "jayeola"
> Net::SSH.start(server, user) do |x|
> cmd2 = x.exec!("test -d /proc && echo \"OK\"").strip
> p cmd2
> if cmd2 != "OK"
> p "no proc found"
> else
> p "got proc"
> end
>
> cmd3 = x.exec!("test -f /proc/partitions && echo \"OK\"")
> cmd4 = x.exec!("test -f /proc/diskstats && echo \"OK\"")
> end
>
>
> I'm using this library and it doesn't give me a prompt at all but runs
> the code as required. How are you using it?


Hi John,
I am using it the same way as you are using. The problem lies
when the initial prompt that is needed gets by-passed when I use the
net/ssh module. I have been usng the net/telnet module initially, where
I get the appropriate prompt on logging in. ie. ">>>". and the shell
prompt is "$" which arises when i do a "!" on the initial prompt.

Telnet works fine, but i am exercising the usage of connecting to the
box thru ssh. So here it by-passes the initial prompt which telnet
module does not.

As telnet looks for a given prompt while logging in, does ssh have such
a prompt?

Also I guess the net/ssh module in ruby creates a instance of the shell
and executed the commands to be executed on that shell rather than
connecting to the actual machine.

- P

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

John Maclean

6/2/2008 12:31:00 PM

0

On Mon, 2 Jun 2008 21:11:05 +0900
Prasad Pednekar <prasadp@gslab.com> wrote:

> John Maclean wrote:
> > On Sun, 1 Jun 2008 18:23:25 +0900
> > Prasad Pednekar <prasadp@gslab.com> wrote:
> >
> >> but
> >> in my case after running the script it goes directly to the shell prompt
> >> "$" by-passing the cli prompt.
> >>
> >> a. Why does this behaviour take place??
> >>
> >> b. Is there a way to go to the initial cli prompt ??
> >>
> >>
> >> -P
> >
> > From `ri Net::SSH`
> >
> > Net::SSH.start("host", "user", :password => "password") do |ssh|
> > result = ssh.exec!("ls -l")
> > puts result
> > end
> >
> >
> > Sample of my own stuff...
> > require 'rubygems'
> > require 'net/ssh'
> >
> > server = "acid"
> > user = "jayeola"
> > Net::SSH.start(server, user) do |x|
> > cmd2 = x.exec!("test -d /proc && echo \"OK\"").strip
> > p cmd2
> > if cmd2 != "OK"
> > p "no proc found"
> > else
> > p "got proc"
> > end
> >
> > cmd3 = x.exec!("test -f /proc/partitions && echo \"OK\"")
> > cmd4 = x.exec!("test -f /proc/diskstats && echo \"OK\"")
> > end
> >
> >
> > I'm using this library and it doesn't give me a prompt at all but runs
> > the code as required. How are you using it?
>
>
> Hi John,
> I am using it the same way as you are using. The problem lies
> when the initial prompt that is needed gets by-passed when I use the
> net/ssh module. I have been usng the net/telnet module initially, where
> I get the appropriate prompt on logging in. ie. ">>>". and the shell
> prompt is "$" which arises when i do a "!" on the initial prompt.
>
> Telnet works fine, but i am exercising the usage of connecting to the
> box thru ssh. So here it by-passes the initial prompt which telnet
> module does not.
>
> As telnet looks for a given prompt while logging in, does ssh have such
> a prompt?
>
> Also I guess the net/ssh module in ruby creates a instance of the shell
> and executed the commands to be executed on that shell rather than
> connecting to the actual machine.
>
> - P
>


session.exec!("some command") runs that command on the remote server. You'll have to use another method to gain a shell session. Have a look at `ri Net::SSH` or use `gem_server` and fire up a browser with localhost:8808, (geddit ?). There __is__ a way to get a shell but I've forgotten what it is. Perhaps the gem termios?