in reply to Re^7: Deleting lines from named.conf file
in thread Deleting lines from named.conf file

many thanks for your support


first the script is running will but it has 2 issues :-
the first issue when i want to delete the first zone like that
zone "foo.com" { type master file path to the zone }; zone "blah.com" { type master file path to the zone }; zone "bar.com" { type master file path to the zone };
if i want to delete the first zone "foo.com" the file doesn't change !!!
the second issue if i want to delete any zone in the middle of the file like "blah.com"there is
a newline created instead of deleted zone the output is like this
zone "foo.com" { type master file path to the zone }; zone "bar.com" { type master file path to the zone };
as u see a white space is created in the place of the deleted zone ,, so i want to eliminate this new line
i think it will done by making the print statement to print the file with a shifted instead of the deleted zone .
finally i want to understand the $comment variable is here what we provide such variable
i knew that $block to count the brackets level and the $comment in the our old example was provided to count the comment level
so what is the value of this variable here
and Really am thankful for you

Replies are listed 'Best First'.
Re^9: Deleting lines from named.conf file
by shmem (Chancellor) on Nov 11, 2007 at 00:21 UTC
    Taking exactly your input file
    zone "foo.com" { type master file path to the zone }; zone "blah.com" { type master file path to the zone }; zone "bar.com" { type master file path to the zone };

    and running the script provided

    qwurx [shmem] ~ > perl zonedel.pl please enter the domain name: foo.com

    I get as result

    zone "blah.com" { type master file path to the zone }; zone "bar.com" { type master file path to the zone };

    Yes, it starts with a blank line, but the zone definition is gone. What the heck did you run? Is it really that difficult to suppress blank lines? I'm running out of advice for you.

    --shmem

    _($_=" "x(1<<5)."?\n".q·/)Oo.  G°\        /
                                  /\_¯/(q    /
    ----------------------------  \__(m.====·.(_("always off the crowd"))."·
    ");sub _{s./.($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e.e && print}
      i have tried to eliminate the blank line that created so i but this line before the print line
      next if /^\s*$/;

      but this suppress any new line in the whole file
      i think i need to provide something like unless /\s/; after printing the line for this zone only
        If you always have your zone definitions separated with blank lines, but no blank lines in the zone blocks, the task is even easier - read and write the file in paragraph mode:
        #!/usr/bin/perl -w -ni.bak -00 use strict; BEGIN { local $/ = "\n"; print "please enter the domain name: "; use vars qw($targetdomain); chomp ($targetdomain = <STDIN>); } print unless /^zone\s+"$targetdomain"/;
        Call that script with the zone file as argument, e.g.
        perl zonedel.pl /home/blackice/hello

        It will create a backup of the file. For the switches after '#!/usr/bin/perl' see perlrun.

        --shmem

        _($_=" "x(1<<5)."?\n".q·/)Oo.  G°\        /
                                      /\_¯/(q    /
        ----------------------------  \__(m.====·.(_("always off the crowd"))."·
        ");sub _{s./.($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e.e && print}
      thanks u are right and sorry for misunderstanding
      i want to ask you also about $comment variable if you wouldn't mind i want to understand what is itis value here itis as i asked you before
      at the end i hope to be like you in a day
      and thanks for every thing