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 :)
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.