Regular expressions

Discussion in 'Perl' started by mark, Jun 30, 2003.

  1. mark

    mark Guest

    i am attempting to write a script using Net::Telnet. The script telnets to
    a machine
    logs in and issues a command to list the config. Tthe output of the command
    pauses
    about every screenfull and gives the user the prompt " --More-- ". The
    script
    contains the followin code to account fot the prompt.

    $telnet->waitfor('/-\-More\-\- $/i');
    $telnet->print('\s');

    the script does not proceed past the " --More-- " prompt. this problems
    seems to have stumpt me. does anyone have any suggestions for me?

    Thanks
    mark
     
    mark, Jun 30, 2003
    #1
    1. Advertising

  2. mark

    Eric Amick Guest

    On Sun, 29 Jun 2003 21:05:50 -0500, "mark" <>
    wrote:

    >i am attempting to write a script using Net::Telnet. The script telnets to
    >a machine
    >logs in and issues a command to list the config. Tthe output of the command
    >pauses
    >about every screenfull and gives the user the prompt " --More-- ". The
    >script
    >contains the followin code to account fot the prompt.
    >
    >$telnet->waitfor('/-\-More\-\- $/i');


    Hyphens are special only within character classes, so I'd remove the
    backslashes for readability if nothing else. Are you absolutely certain
    the prompt ends with exactly one space?

    >$telnet->print('\s');


    This looks suspicious. Shouldn't that be a space in the quotes? You
    probably want put() instead of print(); print() sends out a newline
    automatically, and you wouldn't press return when typing it manually.

    --
    Eric Amick
    Columbia, MD
     
    Eric Amick, Jun 30, 2003
    #2
    1. Advertising

  3. mark

    mark Guest

    "Eric Amick" <> wrote in message
    news:...
    > On Sun, 29 Jun 2003 21:05:50 -0500, "mark" <>
    > wrote:
    >
    > >i am attempting to write a script using Net::Telnet. The script telnets

    to
    > >a machine
    > >logs in and issues a command to list the config. Tthe output of the

    command
    > >pauses
    > >about every screenfull and gives the user the prompt " --More-- ". The
    > >script
    > >contains the followin code to account fot the prompt.
    > >
    > >$telnet->waitfor('/-\-More\-\- $/i');

    >
    > Hyphens are special only within character classes, so I'd remove the
    > backslashes for readability if nothing else. Are you absolutely certain
    > the prompt ends with exactly one space?
    >
    > >$telnet->print('\s');

    >
    > This looks suspicious. Shouldn't that be a space in the quotes? You
    > probably want put() instead of print(); print() sends out a newline
    > automatically, and you wouldn't press return when typing it manually.
    >
    > --
    > Eric Amick
    > Columbia, MD



    ya, i tried exactly one space prior to trying the /s. ya fairly certain it
    is just one space. i was thought it might
    be sending an unprintable character for what ever reason, so i changed
    input_log to a dump_file and checked
    the last character in it. the end of the file just one character with
    character code 20. I just tried using the put in
    place of the print, but didn't seem to help.

    Thanks mark
    mark
     
    mark, Jun 30, 2003
    #3
  4. "mark" <> wrote in message news:<>...
    > i am attempting to write a script using Net::Telnet. The script telnets to
    > a machine
    > logs in and issues a command to list the config. Tthe output of the command
    > pauses
    > about every screenfull and gives the user the prompt " --More-- ". The
    > script
    > contains the followin code to account fot the prompt.
    >
    > $telnet->waitfor('/-\-More\-\- $/i');
    > $telnet->print('\s');
    >
    > the script does not proceed past the " --More-- " prompt. this problems
    > seems to have stumpt me. does anyone have any suggestions for me?


    There could be several problems here.

    First, input buffering could pose a problem. The Net::Telnet documentation
    explicitly states that all input is buffered; in my limited testing,
    the waitfor() method does indeed return lines that do *not* end with an
    end-of-line, but I am not sure that this will always be the case.
    In other words, the problem could be Net::Telnet's waitfor() not returning
    until a whole line has been read, and the --More-- prompt does not really
    contain a CR/LF at the end.

    Second, are you sure that the string you should be matching for is
    the exact sequence of characters '-', '-', 'M', 'o', 'r', 'e', etc?
    I mean, some pagers use the "backspace convention" (for lack of a better
    name that I can think of right now) to indicate bold, underline and such:
    for bold, the pager outputs 'M', backspace, 'M'; for underline, it prints
    '_', backspace, 'M'. If the '--More-- ' prompt is bold for some reason,
    then '--More-- ' will probably not match it.

    Those are two reasons that I can think of offhand.

    G'luck,
    Peter
     
    Peter Pentchev, Jul 3, 2003
    #4
  5. mark

    adey Guest

    On Sun, 29 Jun 2003 21:05:50 -0500, "mark" <>
    wrote:

    >i am attempting to write a script using Net::Telnet. The script telnets to
    >a machine
    >logs in and issues a command to list the config. Tthe output of the command
    >pauses
    >about every screenfull and gives the user the prompt " --More-- ". The
    >script
    >contains the followin code to account fot the prompt.
    >
    >$telnet->waitfor('/-\-More\-\- $/i');
    >$telnet->print('\s');
    >
    >the script does not proceed past the " --More-- " prompt. this problems
    >seems to have stumpt me. does anyone have any suggestions for me?
    >
    >Thanks
    >mark
    >
    >

    Hi Mark,

    I use the module all the time. The non Perl solution to your problem
    is this;

    I would suggest you command the machine to dump the whole of the
    config in one go.

    For instance, if you are attempting to list the config on a Cisco
    router, you could issue the command "term len 0" prior to issuing the
    command to list the config.

    Adey
     
    adey, Oct 28, 2003
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jay Douglas

    Custom Regular Expressions in ASP.net

    Jay Douglas, Nov 2, 2003, in forum: ASP .Net
    Replies:
    3
    Views:
    608
    mikeb
    Nov 3, 2003
  2. Dustin D.
    Replies:
    1
    Views:
    11,213
  3. Dustin D.
    Replies:
    0
    Views:
    2,307
    Dustin D.
    Aug 27, 2003
  4. Jay Douglas
    Replies:
    0
    Views:
    610
    Jay Douglas
    Aug 15, 2003
  5. Noman Shapiro
    Replies:
    0
    Views:
    235
    Noman Shapiro
    Jul 17, 2013
Loading...

Share This Page