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

Hi gurus,

I have been using Perl Telnet module to log into Cisco router to paste in the command, as below, which works fine. In example below, you can see that long command such as "rate-limit input..." has been truncated and a dollar sign ($) appeared indicating that the terminal display for this command has been contracted.

Now I am trying to give it a web interface - invoking the same Perl script. It works but the display from the web is garbled and looks very messy. See example further below.

After close check, I found out those un-printable characters are actually "Back Space", corresponding to ASCII value 008. My interpretation is that while a line getting too long, the terminal issue certain number of "Back Space" to delete excessive characters which could not hold in one line. I counted the number of characters hidden, which is the same as the number of Back Space.

My question (and wish) is to present the output nicer on webpage. There are several challenges for me: 1. snippets of the long command have been echoed back multiple times, interleaved by "Back Spaces". These snippets are overlapping, and some whole word has been broken up by white space or Back Space. 2. If I only keep latter, say 60 characters, as an easier approach, I would lose prompt, such as R1(config-subif)#, which is anchored at begging of the line; 3. my idea is check the output, each time I encounter a Back Space, I go backwards to delete same number of characters, which seems a bit hard to implement.

Any input are appreciated. -- Jun

Below are display from terminal, which show contracted format for long command:
Do you want to proceed with router config? Input "y" to proceed, or "n" to abort y yThe file is:temp_config The router is 150.1.1.1 R1#conf t Enter configuration commands, one per line. End with CNTL/Z. R1(config)#interface FastEthernet0/1.30 R1(config-subif)# bandwidth 10000 R1(config-subif)# encapsulation dot1Q 30 R1(config-subif)# ip address 10.248.223.85 255.255.255.252 R1(config-subif)# no ip redirects R1(config-subif)# no ip unreachables R1(config-subif)# no ip proxy-arp R1(config-subif)# no snmp trap link-status R1(config-subif)# no cdp enable R1(config-subif)# no shutdown R1(config-subif)#$0 conform-action set-prec-transmit 1 exceed-action d +rop R1(config-subif)#$0000 3840000 conform-action transmit exceed-action d +rop R1(config-subif)#end
Below are display from Web for output from the same Perl script, which shows garbled characters (which actually are Back Spaces, ASCII 008):
R1#conf t Enter configuration commands, one per line. End with CNTL/Z. R1(config)#interface FastEthernet0/1.30 R1(config-subif)# bandwidth 10000 R1(config-subif)# encapsulation dot1Q 30 R1(config-subif)# ip address 10.248.223.85 255.255.255.252 R1(config-subif)# no ip redirects R1(config-subif)# no ip unreachables R1(config-subif)# no ip proxy-arp R1(config-subif)# no snmp trap link-status R1(config-subif)# no cdp enable R1(config-subif)# no shutdown R1(config-subif)# rate-limit input 10240000 1920000 3840000 conform-ac +tion se$ +input 10240000 1920000 3840000 conform-action set -p +rec-tra400 +00 1920000 3840000 conform-action set-prec-tran smit + 1 ex000 3 +840000 conform-action set-prec-transmit 1 exc eed-ac +tio conform +-action set-prec-transmit 1 exceed-action  drop R1(config-subif)# rate-limit output 10240000 1920000 3840000 conform-a +ction t$ +output 10240000 1920000 3840000 conform-action tr an +smit ex240 +000 1920000 3840000 conform-action transmit exc eed- +actio0000 +3840000 conform-action transmit exceed-action  drop R1(config-subif)# end

A bit of code snippet just for completeness.

$session->login('user', 'cisco'); $session->enable("cisco123"); # feed in command file line-by-line while (<$tmp_fh>) { my @output = $session->cmd("$_"); print @output; }; $session->close;

Replies are listed 'Best First'.
Re: How to format terminal contraction for long command
by soonix (Chancellor) on Jun 27, 2014 at 07:42 UTC