From: Prasad Pednekar Date: 2008-06-02T21:11:05+09:00 Subject: Re: Usin net/ssh library John Maclean wrote: > On Sun, 1 Jun 2008 18:23:25 +0900 > Prasad Pednekar 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-forum.com/.