in reply to Using Net::Telnet::Cisco toTelnet from Host to Host

Piece o' cake. What you want to do is use a local script to telnet to host1, then from that host telnet to host2, and capture command output, right?

Simply create a telnet object, establishing a connection to host1, print a telnet command to host2 via that object, then tell the object to login again, this time with host2's settings.

I tested this with Net::Telnet, but I suspect it would work with ::Cisco as well. You might also add code to logout gracefully.

#!/perl -w use strict; use Net::Telnet; # Cavaets: # # 1. This simple example assumes that the login, password, and command # prompts are all able to be matched by the Net::Telnet defaults - if # not, you'll need to add the appropriate parameters to the login() # command when logging in to host2. # # 2. I'm not sure $! is going to be meaningful in my die() statements, # but what the heck - insert your own debugging if it's not working. # :-) # First host my $host1 = 'hostname1'; my $user1 = 'user1'; my $pass1 = 'password1'; # Second host my $host2 = 'hostname2'; my $user2 = 'user2'; my $pass2 = 'password2'; my $session = new Net::Telnet (host => $host1) or die "Couldn't create: $!"; $session->login($user1, $pass1) or die "Couldn't login to $host1: $!"; $session->print("telnet $host2") or die "Couldn't telnet to $host2: $! +"; $session->login($user2, $pass2) or die "Couldn't login to $host2: $!"; # Obviously, put your own commands in here - $session is now talking # to host2 via host1. my @output = $session->cmd('uptime') or die "Couldn't run command: $!" +; print "@output"; exit;