John Maclean
6/2/2008 12:31:00 PM
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?