[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Omaha.pm] Split Apache conf file into separate files
By request today...
j
#!/usr/bin/perl
my $read_this_file = "./vhosts.conf";
# Read an Apache conf file w/ multiple VirtualHost directives and
# split each VirtualHost into a separate file.
#
# This'd be cleaner w/ an XML parser (*cough* XML::Twig), but I don't
# know if the user has any XML libraries installed.
#
# 2007-03-02 | Omaha Perl Mongers | http://omaha.pm.org
$/ = '</VirtualHost>';
open (IN, $read_this_file) or die "Unable to open $read_this_file";
while (<IN>) {
s/.*(<VirtualHost)/$1/s;
my ($server_name) = /ServerName (.*)/;
next unless $server_name;
open (OUT, ">$server_name.conf") or die "Unable to write to $server_name.conf";
print OUT $_;
close OUT;
}
close IN;