Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > Telnet - attempting to initiate a telnet session within an established telnet session

Reply
Thread Tools

Telnet - attempting to initiate a telnet session within an established telnet session

 
 
Carcarius
Guest
Posts: n/a
 
      12-06-2007
My company builds a product that has a dual slot architecture for
redundancy. Each slot has 2 significant Ethernet interfaces; one for
network connectivity and one for connectivity between slots. Only one
of the slots is accessible from the network at a time (the other is
meant to be a backup). The two slots communicate via a common
Ethernet backplane and each slot has a different IP address (10.0.0.9
and 10.0.0.10).

I am trying to build a script with Ruby that allows me to first telnet
into the active slot using it's network address (easy - mission
accomplished) but then to also telnet into the backup slot over the
Ethernet backplane within the same telnet session. I want to issue
commands in order to gather data such as uptime, disk usage, etc...

I am getting hung up on the password prompt when trying to connect to
the second slot. I can't seem to send the password info with carriage
return so I can gain access to the second slot and issue additional
commands.

The code I have written is in the testing phase and is clearly not
perfect.

Here is my code:

require 'net/telnet'

top_node = ARGV[0]

tn = Net::Telnet::new( "Host" => top_node,
"Timeout" => 10,
"Prompt" => /[$%#>] \z/n)
tn.login("root", "lab") { |c| print c }
tn.cmd("date") { |c| print c }
print ARGV[0]
print " - "
tn.cmd("./uptime") { |c| print c }
test = tn.cmd("ifconfig eth0 | ifconfig eth0 | awk '/inet addr:/
{print $2 }'")

if test.include?("addr:10.0.0.9")
tnbackup = "10.0.0.10"
else
tnbackup = "10.0.0.9"
end

print "\n\nTelnetting to Backup HFM " + "(" + tnbackup + ")\n\n"

tn.cmd("telnet " + tnbackup + " -l root") { |c| print c }

tn.waitfor(/Password:\s*/im) { |c| print c }
tn.puts("lab")
tn.cmd("ifconfig eth0 | ifconfig eth0 | awk '/inet addr:/ {print
$2 }'") { |c| print c }
tn.cmd("exit") { |c| print c }
tn.close

Has anyone successfully telnet into other devices from within an
established telnet session? Let me know if I am not clear with my
problem and if I need to clarify it more.

Any help is greatly appreciated.

Thanks,

Heath

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
To get from the browser (web client), the server X509 certificate used in an SSL established session paxtra@gmail.com Java 0 08-02-2006 08:02 AM
To get from the browser (web client), the server X509 certificate used in an SSL established session paxtra@gmail.com Javascript 0 08-02-2006 08:02 AM
Wireless Router within established network xFiver Computer Support 10 08-25-2005 09:45 PM
"An error was encountered whilst attempting to start your session. =?Utf-8?B?UmFuZHkgR2FkaW5nYW4=?= ASP .Net 2 05-10-2005 07:48 AM
12016/GRP sending LCP reconfigs on established Multilink PPP session John Hardin Cisco 1 11-10-2004 05:57 PM



Advertisments