Generating Large Numbers of Router Configurations
Problem
You need to generate hundreds of router configuration files for a big network rollout.
Solution
When building a large WAN, you will usually configure the remote branch routers similarly, according to a template. This is a good basic design principle, but it also makes it relatively easy to create the router configuration files. The Perl script in Example 1-1 merges a CSV file containing basic router information with a standard template file. It takes the CSV file as input on STDIN.
Example 1-1. create-configs.pl
#!/usr/local/bin/perl
#
$template_file_name="rtr-template.txt";
while(<>) {
($location, $name, $lo0ip, $frameip, $framedlci, $eth0ip, $x)
= split (/,/);
open(TFILE, "< $template_file_name") || die "config template file $template_file_name: $!\n";
$ofile_name = $name . ".txt";
open(OFILE, "> $ofile_name") || die "output config file $ofile_name: $!\n";
while (<TFILE>) {
s/##location##/$location/;
s/##rtrname##/$name/;
s/##eth0-ip##/$eth0ip/;
s/##loop0-ip##/$lo0ip/;
s/##frame-ip##/$frameip/;
s/##frame-DLCI##/$framedlci/;
printf OFILE $_;
}
}Discussion
This Perl script is a simplified version of much larger scripts that we have used to create the configuration files for some very large networks. We then loaded these configuration files into the routers and shipped them to the remote locations, along with a hard copy of the configuration, in case there were problems during shipment. The technician doing the router installation ...