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

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 (

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

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

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:”)
tnbackup = “”
tnbackup = “”

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.cmd(“ifconfig eth0 | ifconfig eth0 | awk ‘/inet addr:/ {print
$2 }’”) { |c| print c }
tn.cmd(“exit”) { |c| print c }

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.



This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs