before the "show running" command is executed the two commands are setup:
my $paging= $ssh->exec("terminal length 1000"); #we don't like prompts when showing the config
my $paging= $ssh->exec("no page"); #we don't like prompts when showing the config

Message when script backups, every 1000 lines or so we see the following characters:
^[[232;1H^[[2K^[[1000;1H^[[1;1000r^[[1000;1H

we need to have a look on the hex values of the charactes, to build a valid perl regular expression
. [ 2 3 2 ; 1 H . [ 2 K . [ 1 0 0 0 ; 1 H . [ 1 ; 1 0 0 0 r . [ 1 0 0 0 ; 1 H
HEX: 1B 5B 32 33 32 3B 31 48 1B 5B 32 4B 1B 5B 31 30 30 30 3B 31 48 1B 5B 31 3B 31 30 30 30 72 1B 5B 31 30 30 30 3B 31 48 20 20 20

------------------------------
regular expression solution:
------------------------------
if ($line=~/^(.*)\x1b\x5b232\x3b1H\x1b\x5b2K\x1b\x5b1000\x3b1H\x1b\x5b1\x3b1000r\x1b\x5b1000\x3b1H(.*)$/){

------------------------------
in the code it looks like this:
------------------------------
#filter out strange line: ^[[232;1H^[[2K^[[1000;1H^[[1;1000r^[[1000;1H
# . [ 2 3 2 ; 1 H . [ 2 K . [ 1 0 0 0 ; 1 H . [ 1 ; 1 0 0 0 r . [ 1 0 0 0 ; 1 H
#in hex it is: 1B 5B 32 33 32 3B 31 48 1B 5B 32 4B 1B 5B 31 30 30 30 3B 31 48 1B 5B 31 3B 31 30 30 30 72 1B 5B 31 30 30 30 3B 31 48 20 20 20
#print "$lc $line\n";
if ($line=~/^(.*)\x1b\x5b232\x3b1H\x1b\x5b2K\x1b\x5b1000\x3b1H\x1b\x5b1\x3b1000r\x1b\x5b1000\x3b1H(.*)$/){
#print "match found in line $lc: $line!\n";print "1=$1\n";print "2=$2\n";exit;
push @config, ($1.$2);
}else{
push @config, $line;
}

computer2know :: thank you for your visit :: have a nice day :: © 2024