in reply to Re: Net::Telnet::Cisco and prompt regex issue
in thread Net::Telnet::Cisco and prompt regex issue

/ (?m: # not capture, multiline .* # skip anything [\w\.-]+ # the 'device' name part \s? (?:\(config[^\)]*\))? # random '(config...)' part \s? [\$#?>] # real prompt end part \s? (?:\(enable\))? \s* # random '(enable)' part $) /x

You're missing the '\' escape of the '.' in the device part. It's supposed to be a hostname like thing: foo-bar.baz10.com and needs to match a literal period '\.'.

You also may need to set the timeout a bit longer depending on how long it takes to download.

What you really want to do is know the device name in advance, or get it from the last-prompt after you login. Then replace the [\w\.-]+ part of the regex with the actual name of the device.

Replies are listed 'Best First'.
Re^3: Net::Telnet::Cisco and prompt regex issue
by Anonyrnous Monk (Hermit) on Dec 09, 2010 at 09:08 UTC
    You're missing the '\' escape of the '.'

    The dot isn't special inside of a character class, so no escaping required:

    $ perl -E 'say "matched" if "foo-bar.baz" =~ /^[\w.-]+\z/' matched $ perl -E 'say "matched" if "foo-bar:baz" =~ /^[\w.-]+\z/'

    The second case (with ':' in place of '.') doesn't match, because the (unescaped) dot in the pattern stands for a literal dot, not "any character" as it would outside of character classes.

      Looks like the problem had to do with the regex being slightly changed from the recommended Net::Telnet::Cisco prompt. The prompt should be changed from this:
      Prompt => '/(?m:.*[\w.-]+\s?(?:\(config[^\)]*\))?\s?[\$#>]\s?(?:\(enab +le\))?\s*$)/'
      To this:
      Prompt => '/(?m:^[\w.-]+\s?(?:\(config[^\)]*\))?\s?[\$#>]\s?(?:\(enabl +e\))?\s*$)/'
      The key difference being the ^ that marks the beginning of the line