Telnet and 'waitfor'

  • Thread starter David Corticchiato
  • Start date
D

David Corticchiato

Hi,

by reading the man i understood that 'waitfor' method could be used like
this :

waitfor(String => 'Name', Timeout => 30)

But, with that code... :


telnet_session = Net::Telnet.new('Host' => @apc_ip)
# @apc_ip is the ip of the host chosen
telnet_session.waitfor(String => 'User Name', Timeout => 30)


...I have a timeout. Is this a syntax problem ?
 
D

David Corticchiato

Jan said:
Seems like you have to quote your key names, i.e. 'String', "Timeout".

Yes that's right, i made a mistake by writting it on the forum. I'd try
with waitfor(buffer), and my aString buffer is never recognized.
 
D

David Corticchiato

Tim said:
Just curious, but are you trying to connect to an APC Power
Distribution Unit? Your choice of variable names -- @apc_ip -- just
made me think of the APC PDUs we have here at work.

Yes I work with APC PDU. ;)

Try setting 'Output_log' to a filename when you create your telnet
session. This will copy all telnet traffic to the given log file.


Ok, so i tried with function made to that : 'login'. Here is my code :


###################Start of code

require 'net/telnet'

class Host

def initialize(host_ip, apc_ip, slot_number)
@host_ip = host_ip
@apc_ip = apc_ip
@slot_number = slot_number
end

def reboot
telnet_session = Net::Telnet.new('Host' => @apc_ip, 'Output_log' =>
'my_log.txt')
telnet_session.login('LoginPrompt' => 'User Name',
'PasswordPrompt' => 'Password',
'Name' => 'cortdav',
'Password' => 'cortdav')


end

end



Dione = Host.new("3.249.13.36", "3.249.13.24", 2)

Dione.reboot

###################End of code

I obtained in the log :
<<
Trying 3.249.13.24...
Connected to 3.249.13.24.


User Name :So, 'User Name' is what I wait for. But it crashes.
It works if I write :

telnet_session.login('LoginPrompt' => '',
'PasswordPrompt' => '',
'Name' => 'cortdav',
'Password' => 'cortdav')

But the day I'll need to wait for an expression, I will have the same
problem, so I need to find the solution now. Reading and Reading the
docs, and I don't find the problem...
 
T

ts

D> telnet_session.login('LoginPrompt' => 'User Name',

telnet.rb use String#===, in your case, with LoginPrompt

moulon% ruby -e 'p "User Name" === "User Name :"'
false
moulon%

moulon% ruby -e 'p "User Name :" === "User Name :"'
true
moulon%

try to give it a regexp

D> 'PasswordPrompt' => 'Password',



Guy Decoux
 
W

William Crawford

David said:
I obtained in the log :
<<
Trying 3.249.13.24...
Connected to 3.249.13.24.


User Name :
So, 'User Name' is what I wait for. But it crashes.

Could it be that it is waiting for a new line character before matching?
Maybe using 'Prompt' instead of 'String' will work?

Also, it says that it converts the string to a regex anyhow, so why not
try setting Match and trying to get it to work that way. Maybe it's
trying to make it match the whole line or something when you use
'String'.

Just thoughts... I haven't tried to use this yet, and I can't right this
moment, unfortunately.
 
D

David Corticchiato

Thanks everybody for your help.

One by one :

Guy, I didn't understand what you mean, sorry.

William, if it is waiting for a new line character, there is a real
problem with waitfor. In the doc they don't say that.

Tim, You're right i can do it without Ruby, but my work isn't to reboot
only so I want to do that with Ruby for learning how to do.

Paul, you're code can't work with me because you use :

session.login("username","password")

'login', by default wait for the prompt "login". But my prompt is "User
Name", So that doesn't work.

For the regex i tried /^User Name$/ but that doesn't work too, do you
have another idea ?
 
D

David Corticchiato

David said:
For the regex i tried /^User Name$/ but that doesn't work too, do you
have another idea ?

Ok thanks everyone : /^User Name$/ couldn't work because of the ':'.
/User Name/ work !!!!

Thanks a lot all your helps was precious.
 

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

Forum statistics

Threads
474,211
Messages
2,571,100
Members
47,695
Latest member
KayleneBee

Latest Threads

Top