in reply to Re: Net::Telnet variable assignment wacky
in thread Net::Telnet variable assignment wacky

The prompt problem is rife with net::telnet, yeah, but that's not the problem as far as I can see. In the instance where the 'sh run' line is commented out, and all I have running is '@config = $t->cmd("sh ver")' then my input log shows that the command is working. But when I try to print out @config, I get nothing. The only time @config gets assigned a value of any sort is when I precede the array assignment with a bare command like the 'sh run' line.
  • Comment on Re: Re: Net::Telnet variable assignment wacky

Replies are listed 'Best First'.
Re: Re: Re: Net::Telnet variable assignment wacky
by vek (Prior) on Sep 29, 2003 at 17:03 UTC

    bonoboy - Just to clarify, everything works ok when you do this:

    @config = $t->cmd("sh ver");
    But doesn't appear to work doing this:
    my $command = "sh ver"; @config = $t->cmd($command);

    Just want to make sure I understand what the problem is.

    -- vek --
Re: Re: Re: Net::Telnet variable assignment wacky
by gnangia (Scribe) on Sep 29, 2003 at 18:35 UTC
    Few suggestions to try
    - Define your break character (output record separator) (by default it is "\n")
    - Define your router prompt
    - Use dump_log() command to see what's happenning in the session

      Nope, if I do the assignation without a command preceding it, the array is empty.

      And the router prompt is defined (otherwise the 'cmd would time out - I'm checking the input log) and all the commands run on the router. It just doesn't assign anything to the array.

      Now the guy over from me's one works fine, on the same machine. The only functional difference is that his is wrapped in a foreach loop. SO I did that to see if it would fix it, and I think maybe I've found the problem somehow. Take a look at this:

      Ok, first, I've opened the telnet session, and this is the script:

      my @array = ("bob","jones","dick"); foreach my $guys (@array) { print $guys; my @output= $t->cmd("sh clock"); print @output; }

      Ok, now when you run it, you get this:

      [me@mybox me]$ ./script bobjones11:15:49.478 GMT Tue Sep 30 2003 dick11:15:49.482 GMT Tue Sep 30 2003

      See what's happening there? The first two elements of the array are being concatenated. If you shorten the number of elements in the array to just one, it doesn't run at all. Could this be related to my original problem?