Search code examples
regexperlnetwork-programmingcisco

Scripting the cisco banner with Net::Appliance::Session


Has anyone ran into this issue? When the script gets to the banner text the script just hangs.

I am using Net::Appliance::Session

Here is the error I get in debug. The rest of the script inserts code perfectly. I did test what I read about adding a # to the banner for each line. Same result.

banner login +
[   4.092880] tr   nope, doesn't (yet) match (?-xism:[\/a-zA-Z0-9._\[\]-]+ ?(?:\(config[^)]*\))? ?[#>] ?$)
[   4.093124] du   SEEN:
banner login +
[   4.093304] tr   nope, doesn't (yet) match (?-xism:[\/a-zA-Z0-9._\[\]-]+ ?(?:\(config[^)]*\))? ?[#>] ?$)
[   4.305872] du   SEEN:
Enter TEXT message.  End with the character '+'
[   4.306121] tr   nope, doesn't (yet) match (?-xism:[\/a-zA-Z0-9._\[\]-]+ ?(?:\(config[^)]*\))? ?[#>] ?$)
We had an issue when accessing the device : 10.49.216.74
The reported error was : read timed-out at /usr/lib/perl5/site_perl/5.10.0/Net/CLI/Interact/Transport/Wrapper/Net_Telnet.pm line 35

Here is a snip of code.

            my $session_obj = Net::Appliance::Session->new(
                host => $ios_device_ip,
                transport => 'Telnet',
                personality => 'ios',
                timeout => 60,
        );

#interace
        $session_obj->set_global_log_at('debug');
        eval {
                 # try to login to the ios device, ignoring host check
                $session_obj->connect(
                username => $ios_username,
                password => $ios_password,
                #SHKC => 0
        );
        # get our running config
        $version_info = $session_obj->begin_privileged;
        $session_obj->cmd('conf t');
        $session_obj->cmd('line con 0');
        $session_obj->cmd('exec-character-bits 8');
        $session_obj->cmd('international');
        $session_obj->cmd('line vty 0 4');
        $session_obj->cmd('exec-character-bits 8');
        $session_obj->cmd('international');
        $session_obj->cmd('line vty 5 15');
        $session_obj->cmd('exec-character-bits 8');
        $session_obj->cmd('international');
        $session_obj->cmd('exit');
        $session_obj->cmd('no banner login');
        $session_obj->cmd('banner login +');
        $session_obj->cmd('*************************************************************************');
        $session_obj->cmd('*                          test                                         *');
        $session_obj->cmd('*                                                                       *');
        $session_obj->cmd('*************************************************************************');
        $session_obj->cmd('+');
        $session_obj->cmd('no banner MOTD');
        $session_obj->cmd('banner motd +');
        $session_obj->cmd('*************************************************************************');
        $session_obj->cmd('*                          test                                         *');
        $session_obj->cmd('*                                                                       *');
        $session_obj->cmd('*************************************************************************');
        $session_obj->cmd('+');
        $session_obj->cmd('exit');
        $session_obj->cmd('write memory');
        $session_obj->end_privileged;
        # close down our session
        $session_obj->close;
};

Solution

  • Took way too long to figure this out... spaces are not your friend.

    $session_obj->cmd("banner login + \rline1\rline2\rline3\r+");
    

    Example with my orginal problem:

    $session_obj->cmd('*************************************************************************\r*                          test                                         *\r*                                                                  *\r*************************************************************************');