I need sort Cisco configs to report but i cannot do the script to made this:
#### INPUT #####
Code:
config-register 0x2102
version 12.2
!
hostname Router
!
interface Ethernet0
description Red LAN
ip address 192.168.1.1 255.255.255.0
no cdp enable
!
interface Serial0
description Red WAN
ip address 172.16.1.1 255.255.255.0
!
interface loopback0
shutdown
!
line con 0
exec-timeout 20 0
stopbits 1
!
line vty 0 4
exec-timeout 20 0
transport preferred none
!
end
### OUTPUT ###
Code:
config-register 0x2102
version 12.2
hostname Router
interface Ethernet0 description Red LAN
interface Ethernet0 ip address 192.168.1.1 255.255.255.0
interface Ethernet0 no cdp enable
interface Serial0 description Red WAN
interface Serial0 ip address 172.16.1.1 255.255.255.0
interface loopback0 shutdown
line con 0 exec-timeout 20 0
line con 0 stopbits 1
line vty 0 4 exec-timeout 20 0
line vty 0 4 transport preferred none
end
Can someone help me with this?, I was trying with awk, grep, etc but I failed.
Thanks
Last edited by Scott; 10-27-2010 at 03:42 PM..
Reason: Please use code tags
It works fine for the example, thanks a lot, but have an additional issue.
If the configuration has the following statements:
### INPUT ###
Code:
!
class-map match-all critical
match ip dscp af31
class-map match-all video
match ip dscp ef
!
### OUTPUT must be ###
Code:
class-map match-all critical match ip dscp af31
class-map match-all video match ip dscp ef
### The idea is each parameter is linked with its own parameters ###
I thought something like that "^interface"... "^class-map .. etc.
head -2 input >>ouput
tail +3 input | { read prev
while read a
do
if [[ $prev = "!" ]]
then
first=$a
else
if [[ "$a" != "!" ]]
then
printf "%s %s\n" "$first" "$a"
else
if [[ $prev = $first ]]
then
print "$first"
fi
fi
fi
prev=$a
done } >>ouput
euh ...
it wouldn't handle the case
Code:
!
class-map match-all critical
match ip dscp af31
class-map match-all video
match ip dscp ef
!
but only
Code:
!
class-map match-all critical
match ip dscp af31
!
class-map match-all video
match ip dscp ef
!
!RANCID-CONTENT-TYPE: cisco
!
!
! model 2600
!
!
config-register 0x2102
version 12.2
service timestamps debug datetime msec localtime
service timestamps log datetime msec localtime
!
hostname Router
!
boot-start-marker
boot-end-marker
!
logging buffered 64000
logging rate-limit 10
logging console critical
!
aaa new-model
!
!
aaa session-id common
ip subnet-zero
ip source-route
!
!
ip cef
ip name-server 172.16.1.1
ip name-server 172.16.1.2
!
!
class-map match-any video
match dscp ef
match ip precedence 5
class-map match-any critical
match dscp af31
!
policy-map qos1
class video
priority percent 75
class critical
bandwidth percent 23
policy-map qos2
class video
police 10000 8000 16000 conform-action transmit exceed-action drop violate-action drop
!
!
interface Loopback0
ip address 1.1.1.1 255.255.255.255
no ip redirects
!
interface FastEthernet0/1
description Red WAN
ip address 192.168.1.1 255.255.255.252
no ip redirects
no ip proxy-arp
no cdp enable
service-policy output qos1
!
interface FastEthernet0/2
description Red LAN
ip address 172.16.1.1 255.255.255.252
no ip redirects
no ip proxy-arp
no ip mroute-cache
no cdp enable
service-policy output qos1
!
interface FastEthernet0/2
shutdown
!
!
router bgp 65000
no synchronization
bgp always-compare-med
bgp log-neighbor-changes
bgp deterministic-med
redistribute connected route-map CONNECTED
redistribute static route-map STATIC
neighbor 172.16.1.2 remote-as 65001
neighbor 172.16.1.2 description PRUEBA
neighbor 172.16.1.2 default-originate
neighbor 172.16.1.6 remote-as 65001
neighbor 172.16.1.6 description PRUEBA
neighbor 172.16.1.6 default-originate
no auto-summary
!
address-family vpnv4
neighbor 172.16.1.2 activate
neighbor 172.16.1.2 send-community both
neighbor 172.16.1.6 activate
neighbor 172.16.1.6 send-community both
exit-address-family
!
ip classless
ip route 10.0.0.0 255.255.255.0 192.168.1.1
ip route 172.16.2.0 255.255.255.0 172.16.1.2
!
ip access-list 10 permit any
!
route-map test permit 10
match address 10
!
route-map test permit 20
match address 45
!
snmp-server community test
snmp-server trap-source Loopback0
!
control-plane
!
banner motd ^CC
# EQUIPO PRIVADO #
^C
!
line con 0
exec-timeout 20 0
line aux 0
exec-timeout 20 0
transport input telnet
stopbits 1
line vty 0 4
exec-timeout 20 0
transport preferred none
transport input telnet ssh
!
ntp update-calendar
ntp server 10.1.1.1
end
##### EXPECTED OUTPUT ####
!RANCID-CONTENT-TYPE: cisco
!
!
! model 2600
!
!
config-register 0x2102
version 12.2
service timestamps debug datetime msec localtime
service timestamps log datetime msec localtime
hostname Router
boot-start-marker
boot-end-marker
logging buffered 64000
logging rate-limit 10
logging console critical
aaa new-model
aaa session-id common
ip subnet-zero
ip source-route
ip cef
ip name-server 172.16.1.1
ip name-server 172.16.1.2
class-map match-any video match dscp ef
class-map match-any video match ip precedence 5
class-map match-any critical match dscp af31
policy-map qos1 class video
policy-map qos1 class video priority percent 75
policy-map qos1 class critical
policy-map qos1 class critical bandwidth percent 23
policy-map qos2 class video
policy-map qos2 class video police 10000 8000 16000 conform-action transmit exceed-action drop violate-action drop
interface Loopback0 ip address 1.1.1.1 255.255.255.255
interface Loopback0 no ip redirects
interface FastEthernet0/1 description Red WAN
interface FastEthernet0/1 ip address 192.168.1.1 255.255.255.252
interface FastEthernet0/1 no ip redirects
interface FastEthernet0/1 no ip proxy-arp
interface FastEthernet0/1 no cdp enable
interface FastEthernet0/1 service-policy output qos1
interface FastEthernet0/2 description Red LAN
interface FastEthernet0/2 ip address 172.16.1.1 255.255.255.252
interface FastEthernet0/2 no ip redirects
interface FastEthernet0/2 no ip proxy-arp
interface FastEthernet0/2 no ip mroute-cache
interface FastEthernet0/2 no cdp enable
interface FastEthernet0/2 service-policy output qos1
interface FastEthernet0/2 shutdown
router bgp 65000 no synchronization
router bgp 65000 bgp always-compare-med
router bgp 65000 bgp log-neighbor-changes
router bgp 65000 bgp deterministic-med
router bgp 65000 redistribute connected route-map CONNECTED
router bgp 65000 redistribute static route-map STATIC
router bgp 65000 neighbor 172.16.1.2 remote-as 65001
router bgp 65000 neighbor 172.16.1.2 description PRUEBA
router bgp 65000 neighbor 172.16.1.2 default-originate
router bgp 65000 neighbor 172.16.1.6 remote-as 65001
router bgp 65000 neighbor 172.16.1.6 description PRUEBA
router bgp 65000 neighbor 172.16.1.6 default-originate
router bgp 65000 no auto-summary
router bgp 65000 address-family vpnv4
router bgp 65000 neighbor 172.16.1.2 activate
router bgp 65000 neighbor 172.16.1.2 send-community both
router bgp 65000 neighbor 172.16.1.6 activate
router bgp 65000 neighbor 172.16.1.6 send-community both
router bgp 65000 exit-address-family
ip classless
ip route 10.0.0.0 255.255.255.0 192.168.1.1
ip route 172.16.2.0 255.255.255.0 172.16.1.2
ip access-list 10 permit any
route-map test permit 10 match address 10
route-map test permit 20 match address 45
snmp-server community test
snmp-server trap-source Loopback0
control-plane
banner motd ^CC
# EQUIPO PRIVADO #
^C
line con 0 exec-timeout 20 0
line aux 0 exec-timeout 20 0
line aux 0 transport input telnet
line aux 0 stopbits 1
line vty 0 4 exec-timeout 20 0
line vty 0 4 transport preferred none
line vty 0 4 transport input telnet ssh
ntp update-calendar
ntp server 10.1.1.1
end
Is there an easy way to stack Cisco 2960-S and Cisco 2960X switches? If you have no idea, follow this:
1. Stacking is not supported on switches running the LAN Lite image. All switches in the stack must be running the LAN Base image.
2. In a mixed stack of Catalyst 2960-X and Catalyst 2960-S... (0 Replies)
I know there are better ways to do this.
I prefer snmp. I do not have the proper perl modules loaded on the platorm. Snmp isnt loaded on the platform. Telnet is not an option. I need to write an expect script to pull cisco equipment configs.
The following code is executed once I gain... (0 Replies)
Hello all -
I am to this forum and fairly new in learning unix and finding some difficulty in preparing a small shell script. I am trying to make script to sort all the files given by user as input (either the exact full name of the file or say the files matching the criteria like all files... (3 Replies)
hi All, is there a way in linux to loop thru all variables sourced?
i have a set configs like
A=100
b=200
c=400
i can add the above lines to a file and source - so that $A will be 100 .. like wise
now when i do a cut -c 1-2 file.txt |sort | uniq -c on a file it returns me
A 100
B 50
c... (1 Reply)
Hi,
I'm somewhat new to unix OS
and I'm at course for programmers in my country.
and in the course we learn unix and how to script in unix. of course we just started and we learned only the very basic, but I'm a really computer freak and I looking for a way to make the course easier on all of... (8 Replies)
I'm trying to write a login script to ssh into a cisco switch that will run some command remotely. Similar to this expect script located here:
SSH login expect shell script to supply username and password
However, that script does not work with cisco ios. Anyway know what the best way to... (1 Reply)