I am writing a script to track changes in my routing tables. The script pulls down a snapshot of the routing table every 5 minutes and diffs the table against the version that is 5 minutes old. If there is a deviation in the file, the script generates an email. The problem is each line also has an age counter that represents how old the route is, so this field is always changing. Here is a modified snapshot from a production router:
EDIT Routes with seconds and minutes age have been added for completeness.
B* 0.0.0.0/0 [200/0] via 1.0.10.121, 1d13h
[200/0] via 1.0.10.111, 1d13h
10.0.0.0/8 is variably subnetted, 159 subnets, 7 masks
O N1 10.0.0.1/32 [210/21] via 172.18.10.27, 1d13h, Vlan1503
O N1 10.1.0.0/16 [210/21] via 172.18.10.51, 2d17h, Vlan1506
O N1 10.2.0.0/16 [210/21] via 172.18.10.59, 2d17h, Vlan1507
B 10.10.0.0/16 [200/0] via 0.0.0.0, 2d17h, Null0
B 10.186.14.0/24 [200/0] via 1.0.10.124, 1d13h
[200/0] via 1.0.10.114, 1d13h
B 10.186.15.0/24 [200/0] via 1.0.10.124, 1d13h
O N2 10.192.32.0/21 [210/20] via 172.18.10.243, 2d17h, Vlan1508
O N2 10.192.40.0/21 [210/20] via 172.18.10.243, 2d17h, Vlan1508
B 10.193.0.0/24 [200/0] via 1.0.10.124, 1d13h
[200/0] via 1.0.10.114, 1d13h
C 172.18.10.232/29 is directly connected, Vlan1589
L 172.18.10.233/32 is directly connected, Vlan1589
B 205.1.2.3/27 [200/21] via 1.0.30.5, 2d17h
B 205.3.2.1/24 [200/20] via 1.0.30.5, 2d17h
O N1 2.2.2.2 [110/2] via 192.168.0.2, 00:08:48, Vlan1500
O N1 10.10.83.0/24 [210/21] via 172.18.10.27, 00:00:48, Vlan1503
Note all the "2d17h," "1d13h," etc, these are the age counters that are forever increasing until a device goes down or a link flaps, then they reset. However, the age of the route isn't all that important to me, just that the route is present and the "next hop" (aka via) has not changed. Otherwise I would just "wc -l" the two files and make sure the length was the same.
Is it feasible to strip the age counters from the file and then diff them? If so, what is the best way to remove the counters?
Thanks!
EDIT The desired output would be identical but have the age counters removed, like the following:
B* 0.0.0.0/0 [200/0] via 1.0.10.121,
[200/0] via 1.0.10.111,
10.0.0.0/8 is variably subnetted, 159 subnets, 7 masks
O N1 10.0.0.1/32 [210/21] via 172.18.10.27, , Vlan1503
O N1 10.1.0.0/16 [210/21] via 172.18.10.51, , Vlan1506
O N1 10.2.0.0/16 [210/21] via 172.18.10.59, , Vlan1507
B 10.10.0.0/16 [200/0] via 0.0.0.0, , Null0
B 10.186.14.0/24 [200/0] via 1.0.10.124,
[200/0] via 1.0.10.114,
B 10.186.15.0/24 [200/0] via 1.0.10.124,
O N2 10.192.32.0/21 [210/20] via 172.18.10.243, , Vlan1508
O N2 10.192.40.0/21 [210/20] via 172.18.10.243, , Vlan1508
B 10.193.0.0/24 [200/0] via 1.0.10.124,
[200/0] via 1.0.10.114,
C 172.18.10.232/29 is directly connected, Vlan1589
L 172.18.10.233/32 is directly connected, Vlan1589
B 205.1.2.3/27 [200/21] via 1.0.30.5,
B 205.3.2.1/24 [200/20] via 1.0.30.5,
O N1 2.2.2.2 [110/2] via 192.168.0.2, , Vlan1500
O N1 10.10.83.0/24 [210/21] via 172.18.10.27, , Vlan1503
What I am trying to prevent is two identical tables (same amount of routes, same next hops) failing a diff because one of the routes age counters ticked over in between snapshots of the routing tables. Example:
- Script takes snapshot of routing table, all is good, but one route has an age of 00:59:59 (59 minutes and 59 seconds)
- 5 minutes later script takes a snapshot of the routing table, no routes have been removed or added but the diff between the current table and the 5 minute old table fails because the route that was 00:59:59 is now 1d0h old (I'm assuming the counter would be 1d0h, need to confirm it's not 2d1h)
So the idea is if I strip all the age counters out the diffs wont fail. This might not be best way to accomplish my goal of monitoring routing tables. Unfortunately I don't have a strong background in scripting or programming. However I am open to ideas and all suggestions are welcome. :)