[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

Getting the result of a command with Net::Telnet

Ronald Fischer

1/8/2007 10:35:00 AM

Please have a look at the following simple Ruby statement (tn is
a Net::Telnet object):

tn.login(....)
tn.cmd({'String' => 'uname -n', 'Match' => /root@sb.*# */}) {
puts "string received:"
puts str
}

When I run this, I see the result:

string received:
u
string received:
name -n
sb1-1
root@sb1-1:~#

That is, I get the response in two pieces: First the first character
only ("u"), then the rest.

Is there a way to get everything in one piece?

Or might there even be a clever way, which would let me see just
the result of the uname -n command ("sb1-1"), but neither the echoing
of "uname -n", nor the subsequent prompt ("root@sb1-1:~#")? Of
course I can easily extract the required information by myself,
but this seems such a common thing to do (send a command via telnet
and analyze what comes back) that I wonder whether there existed
an easier way to do it.

Ronald



--
Ronald Fischer <ronaldf@eml.cc>
Posted via http://www.news...

1 Answer

Rodrigo Bermejo

1/8/2007 8:36:00 PM

0

Ronald Fischer wrote:
> Please have a look at the following simple Ruby statement (tn is
> a Net::Telnet object):
>
> tn.login(....)
> tn.cmd({'String' => 'uname -n', 'Match' => /root@sb.*# */}) {
> puts "string received:"
> puts str
> }


tn.login(....)
str = tn.cmd('uname -n').chop
p str

Does it works for you ?

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