Flynt has asked for the wisdom of the Perl Monks concerning the following question:

Hello All,

I'll try to ask this as clearly as I can. Can't seem to find an answer to how to fix this. Currently I am using the telnet module to login to a machine and retrieve information using a simple info command(it retrieves machine type, serial number, MAC addresses, etc.) The problem I am having is the output contains -> as one of the MAC address entries.

When I get to that entry, perl stops trying to gather more data and my script stops. Here's the snippet of code. As you can see, it's very simple.

$telnet->print("info -T system:$target"); @infosyst=$telnet->waitfor('/>/i');

Now I can also just print the result with print $telnet->waitfor('/>/i'); Either way, the output is the same

Where I should receive this as the output

MAC Address 1: 00:1A:64:85:B2:C0 -> 00:1A:64:85:B2:CF
MAC Address 2: Not Available
MAC Address 3: Not Available
MAC Address 4: Not Available
MAC Address 5: Not Available
MAC Address 6: Not Available
MAC Address 7: Not Available
MAC Address 8: Not Available

I receieve this and the script stops
MAC Address 1: 00:1A:64:85:B2:C0 ->

How do I tell it to ignore that as a command? telnetmode does not work for this case.

All help appreciated,

Replies are listed 'Best First'.
Re: Perlnet Telnet issue with ->
by bv (Friar) on Jan 15, 2010 at 20:26 UTC

    From the documentation for Net::Telnet

    This method reads until a pattern match or string is found in the input stream

    So your program is stopping once it reaches the >, thinking it is the next prompt. You should probably change that regex to match something more specific. At the very least, try /[^-]>/ to avoid the specific instance you are seeing. But really, learn more about the modules you are using. The use of the /i modifier (which has no significance when matching only symbols) seems to indicate that you copy-and-pasted this code without completely understanding it.

    print map{substr'hark, suPerJacent other l',$_,1}(11,7,6,16,5,1,15,18..23,8..10,24,17,0,12,13,3,14,2,4);
Re: Perlnet Telnet issue with ->
by MidLifeXis (Monsignor) on Jan 15, 2010 at 20:19 UTC

    waitfor is awaiting a pattern - the > symbol. You will need to be more specific in your waitfor call, change your prompt, filter the program output to remove the prompt characters, or something similar.


Re: Perlnet Telnet issue with ->
by keszler (Priest) on Jan 15, 2010 at 20:30 UTC
    Your waitfor is a regular expression consisting of a single > character; I assume that's part or all of the system prompt that appears when the info command is complete. The problem is that the > character appears in the output of the info command.

    The solution is to waitfor something else. If there are other characters that always appear in the system prompt, include them in the waitfor regex.

    A fragile solution is to waitfor a > not preceeded by a dash, as in the info command's output. A regex for this:

    # match > at the beginning of a line or not preceeded by - @infosyst=$telnet->waitfor('/(\A|[^-])>/');
Re: Perlnet Telnet issue with ->
by Flynt (Initiate) on Jan 17, 2010 at 17:38 UTC
    Thank all of you for your help. I was automatically assuming a more complicated issue and overlooked what was simply right in front of my face. I changed my waitfor to look for system> which is the full prompt and things are peachy now. Appreciate your patience in answering.