The INPUT.txt will be having the all the below IP prefixes(4.21.103.0/24,10.10.10.0/24 & 212.54.129.0/24 etc..).After telnetting the router it will execute the below commands and below will be the expected output of the commands.From the below outputs it has to search string "best" and below its use all the values againt string "Community:" and AS path values marked bold black & associated to "best" keywords stanza.So the output would look like as below in a text format.#./cisco.pl INPUT.txt OUTPUT.txt
4.21.103.0/24 | 4525:197 4525:1790 4525:1111 | 7323 3549 46133 10.10.10.0/24 | % Network not in table 212.54.129.0/24 | 4525:197 4525:1790 | Local
Below is the script which need to be modified to meet the above results after executing the command "sh ip bgp $prefix"router>sh ip bgp 4.21.103.0/24 BGP routing table entry for 4.21.103.0/24, version 336364302 Paths: (7 available, best #4) 7423 3549 703 192.168.248.5 (metric 29) from 192.168.103.28 (192.168.103.28) Origin IGP, metric 0, localpref 50, valid, internal Community: 4525:197 4525:1790 4525:9111 Originator: 209.64.228.126, Cluster list: 102.108.201.228 7323 3549 46133 192.168.238.5 (metric 29) from 192.168.103.27 (192.168.103.28) Origin IGP, metric 0, localpref 50, valid, internal,best Community: 4525:197 4525:1790 4525:1111 Originator: 209.64.228.126, Cluster list: 102.108.201.228 router>sh ip bgp 10.10.10.0/24 % Network not in table router>sh ip bgp 212.54.129.0/24 BGP routing table entry for 212.54.129.0/24, version 332786588 Paths: (3 available, best #3) Local, (Received from a RR-client) 212.54.45.235 from 212.54.45.235 (212.54.33.154) Origin IGP, metric 2, localpref 100, valid, internal Community: 4525:197 4525:1790 4525:9111 Local 212.54.33.153 from 0.0.0.0 (212.54.33.153) Origin IGP, metric 11, localpref 100, valid, local, best Community: 4525:197 4525:1790
Need commands after chomp;. Anticipating a quick and favourable response. Best Rgds Amit.#!/bin/perl use Net::Telnet::Cisco; $router = "10.10.10.4"; $port = 23; my $cs = Net::Telnet::Cisco->new( Host => $router, Input_log => "Input22.log", Port => $port,); $cs->login( 'cisco', 'cisco' ); $password="cisco123"; $cs->enable( $password ); open(OUTPUT, "> $ARGV[1]") or die "ERROR opening $ARGV[1]: $!n"; open(PREFIXES, "< $ARGV[0]") or die "ERROR opening $ARGV[0]: $!n"; open(ASFILE, "< asnames.txt") or warn "Can not open asnames.txt: $!n"; while (<ASFILE>) { /AS(d+?) (.*)/; $as{$1} = "$2"; } close(ASFILE); $path_num = 0; @cmd_output = $cs->cmd( 'term len 0' ); while (<PREFIXES>) { chomp; if (!/^#/) { $prefix = $_; @cmd_output = $cs->cmd( "sh ip bgp $prefix" ); foreach (@cmd_output) { chomp;
In reply to Need help on perl for Cisco router command execution. by amit_singh
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |