hello all
i want to make a perl script that : -
1.) ask user to enter the domain name which is in the zone that will be commented .
2.) search in the named.conf file for a multi line string including domain that entered by the user
2.) comment out the whole zone that including the matching domain name , from the empty line before the zone name and then to a five lines "to comment all the zone part .
here is a sample of that file :
zone "dontchangethisdomain.com" {
type master;
file "/somepath/to/dontchangethisdomain.com";
notify yes;
}
zone "mydomain.com" {
type master;
file "/path/to/zone/mydomain.com";
notify yes;
}
zone "leavethisalonetoo.com" {
type master;
file "/other/path/to/leavethisalonetoo.com";
notify yes;
}
i worte that code and i cannot figure out what to do next
#!/usr/bin/perl -w
use strict;
print " please enter the domain name: ";
my $targetdomain = <STDIN>;
chomp $targetdomain;
my $file = "/home/blackice/hello";
open HAN,$file || die "error opening file: $!";
while (<HAN>) {
if ( $file =~ m/\n(.?)zone "$targetdomain"
\{\n(.*)type(.*);\n(.*)file(.*);\n(.*)notify(.*);\ n(.?)\}/is)
first: i asked the user to enter the domain for the zone that will be commented .
then i open the file by a file handler and search with a matching string for a matching zone that include tha $targetdomain which is
entered by the user .
i just finished at here but how i can comment the lines of the zone starting from the empty line before the zone name till the last '}'
without affecting other zones ...
sorry for the long thread and any help will be appreciated :)