Usin net/ssh library

  • Thread starter Prasad Pednekar
  • Start date
P

Prasad Pednekar

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
 
J

John Maclean

=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?
 
P

Prasad Pednekar

John said:
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
 
J

John Maclean

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?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top