yields nothing to the screen, I figured out why though.. the terminal length setting was 25, the cisco default so I:my $router = new Net::Telnet::Cisco(Host => $ip); my @output = $router->cmd("sh users"); print @output;
still nothing.. the script timed out waiting for the prompt to return. so I just out on a limb:$router->cmd("terminal length 0");
now I have something, so I thought, "Great, lets put this into production". so I did.. the results, are incredibly inconsistant, obviously because this was a bad work around. so I think "hey, I've worked with sockets before, I'll just write my own interface to this tricky situation!" so I did.. but I've been toying with the issuing multiple commands to routers using send() and recv() and autoflushing the socket, no luck and I've tried it many different ways, one of which I though should work:$router->cmd("terminal length 0"); $router->cmd("terminal length 0"); my @output = $router->cmd("sh users"); print @output;
what happens here is even though the prompt matched previously, it isn't matching again, and is getting printed at the "elsif($get_output)", thus never issuing the next command and only getting to the first server cuz it halts the recv() ..... I can't see how this could happen, but perhaps others could slap me in the right direction.foreach my $server (@SERVERS) { my ($sname,$sdom); if($server =~ /^([^.]+)(.+)/) { $sname = $1; $sdom = $2; $sdom =~ s/\./\\\./g; } print "\n\n---> Trying $server .... "; socket(ROUTER,AF_INET,SOCK_STREAM,getprotobyname('tcp')); my $sin = sockaddr_in(23,inet_aton($server)); connect(ROUTER,$sin); # or die "$server needs a kick!\n"; print "Connected.\n"; bind(ROUTER,$sin); # below insight provided by Net::Telnet.pm select((select(ROUTER), $|=1)[$[]); #don't buffer writes # end insight. send(ROUTER, "\n", ''); #doing to get a prompt +, establish connection my $task= scalar @CMDS; my $line=""; my $get_output=0; my $i=0; my %OUT=(); while(recv(ROUTER,$line,$LENGTH,'')) { local $_ = lc($line); if(/^$sname($sdom)?\>/) { #we have a prompt if(!$task) { #we're done! send(ROUTER, $close, ''); last; } else { send(ROUTER, $CMDS[$i], ''); $i++; $task--; $get_output=1; next; } } elsif($get_output) { #we're between two pro +mpts and interested in the output push @{ $OUT{$CMDS[$i-1]} }, $line; print $line; } } close ROUTER; }
In reply to Interesting Dilemma by reyjrar
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |