DavisTasar has asked for the wisdom of the Perl Monks concerning the following question:
This is a method I wrote that takes four arguments, the target of the telnet connection, username, password, and an array of commands. For right now, I'm just using the global usernames and passwords ($username $password respectively) because there was an issue with something else. $verbose is a flag that I pass, and in this case it's set to true. logging is another method I wrote to handle output accordingly, but with $verbose being true, I should see it on the console. The code is able to authenticate, and run the commands, but my output isn't present. When I check the dump_log and input_log, the raw (and formatted) text is present, and shows that I'm actually executing the commands and seeing the output, yet, when I try to check the output, it comes back with a "":sub telnet_connection{ my $targetHost = $_[0]; #my $uname = $_[1]; #my $pword = $_[2]; my @listOfCommands = @{$_[3]}; if($verbose){print "\t\tAttempting telnet connection to $targe +tHost\n"; } eval{ $telnet = Net::Telnet->new( Timeout=>5, Errmode=>'retu +rn', dump_log=>"dump_log.txt", input_log=>"input_log.txt"); $telnet->open($targetHost); $telnet->waitfor('/Username: $/i'); $telnet->print($username); $telnet->waitfor('/PASSCODE: $/i'); $telnet->print($password); $telnet->waitfor('/\>/'); #for(my $j=0; $j le scalar @listOfCommands; $j++) foreach my $command (@listOfCommands) { if($verbose) { print "\t\tClient: " . $targetHost +. " Command: $command\n"; } if($verbose) { print "\t\tExecuting command: $comm +and\n"; } my @output = $telnet->cmd($command); if($verbose) { print "OUTPUT:\n"; print @output; } logging($targetHost, \@output, "0"); } $telnet->close(); }; if($telnet->errmsg) { logging($targetHost,$telnet->errmsg,"1"); print $@; } }
And I'm just not sure where to troubleshoot from here. I've looked through several of the stack overflow and perlmonks posts already on Telnet in Perl, but not much help was found there. When I use warnings or use strict, there aren't any issues in this sub.Telnet to <targetIPAddress> Attempting telnet connection to <targetIPAddress> Client: <targetIPAddress> Command: who Executing command: who OUTPUT:
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Perl, Telnet, and No Output
by aitap (Curate) on Aug 13, 2014 at 18:57 UTC | |
by DavisTasar (Initiate) on Aug 13, 2014 at 19:25 UTC | |
|
Re: Perl, Telnet, and No Output
by fishmonger (Chaplain) on Aug 13, 2014 at 16:23 UTC | |
by DavisTasar (Initiate) on Aug 13, 2014 at 16:58 UTC | |
by DavisTasar (Initiate) on Aug 13, 2014 at 17:14 UTC |