I have a CSV file that I need to merge using the following Perl code, but I am not able to run it. It is supposed to out put multiple text files, but it is not working.
#!/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 $_;
}
}
The CSV file looks like this
Toronto, Router1, 172.25.15.1, 172.25.16.6,101, 172.25.100.1
And this the rtr-template.txt file
!
version 12.1
service timestamps debug datetime msec
service timestamps log datetime msec
service password-encryption
!
hostname ##rtrname##
!
enable password cisco
enable secret cisco
!
interface Loopback0
ip address ##loop0-ip## 255.255.255.255
!
interface Serial0/0
description Frame-Relay Circuit
no ip address
encapsulation frame-relay
ip route-cache policy
frame-relay lmi-type ansi
no shutdown
!
interface Serial0/0.1 point-to-point
ip address ##frame-ip## 255.255.255.252
frame-relay interface-dlci ##frame-DLCI##
!
interface FastEthernet0/1
description User LAN Segment
ip address ##eth0-ip## 255.255.255.0
no shutdown
!
router eigrp 99
network 172.25.0.0
!
snmp-server location ##location##
!
line con 0
password cisco
login
transport input none
line aux 0
password cisco
login
line vty 0 4
password cisco
login
transport input telnet
!
end
Aucun commentaire:
Enregistrer un commentaire