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 (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

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