in reply to Deleting lines from named.conf file

Maybe zonemaster is 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}
  • Comment on Re: Deleting lines from named.conf file

Replies are listed 'Best First'.
Re^2: Deleting lines from named.conf file
by firewall00 (Acolyte) on Nov 10, 2007 at 19:04 UTC
    hello Shmem how are i would thank your for you help
    but i cannot really understand the code of the zone master the link you provided in your replay
    and as i saw this zone master depend on connection to database not reladted to a file .
    and i will be thankful if you could help me
      The answers to your very first post here provided all you need to do the task. I gave you a solution which can be tweaked to not comment lines out, but not print them instead (untested):
      my $comment = 0; my $block = 0; while(<$in>) { if (/^zone\s+"$targetdomain"/) { $comment++; $block += () = /(\{)/g; # print $out '// '.$_; next; } if($comment) { $block += () = /(\{)/g; s!^!// ! if $comment or $block; $block -= () = /(\})/g; $comment = 0 unless $block; } print $out $_ unless $comment; }

      Since that trivial task seems to be too difficult for you, I gave you a link to a tool which handles all things zone file related. Yes, it relies on a database, but if you have to do more than casual changes to zone files, for which you could also fire up your editor and do changes by hand, it is the right way to go.

      --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}
        s!^!// ! if $comment or $block;

        What does that do? (I know it's untested code, but still...)

        thanks shmem but why you describe my task as trivial
        i want to let you know that i have tried many times before i posted here and i search google and also used the super search provided here and i cannot solve it
        so i provide a description of what is the problem and the way i thought that will solve the problem like as i mentioned before
        #the first part of the code as the same last code i provided #!/usr/bin/perl -w use strict; print " please enter the domain name: "; my $targetdomain = <STDIN>; my $susdate = `date -u "+%m/%d/%Y %H:%M"`; my $char = "This Domain is Suspended at "; chomp $targetdomain; my $file = "/home/adam/Desktop/hello"; rename $file, "$file.bak" or die "Can't rename file '$file': $!\n"; open my $in, '<', "$file.bak" or die "Can't read file '$file': $!\n"; open my $out, '>', $file or die "Can't write file '$file': $!\n"; my $block = 0; while(<$in>) { if (/^zone\s+"$targetdomain"/) { #here i want to start to deleting lines i think it will done by s// /; #by replacing the lines with an empty lines #then i need to increase the $block by 1 to add the first #open bracke +t by using $block += () = /(\{)/g; #then i want to make something like condition if the block #variable i +s exist add one also to block and then continue #deleting lines if ($block) { s// /; #or if it find a closed bracket decrease the $block by $block -= () = /(\})/g; #and if the block equal to 0 stop deleting lines #then print the output
        i just want to provide some of what i think about my program
        by the way the code you provide me didn't work
        my $comment = 0; my $block = 0; while(<$in>) { if (/^zone\s+"$targetdomain"/) { $comment++; $block += () = /(\{)/g; # print $out '// '.$_; next; } if($comment) { $block += () = /(\{)/g; s!^!// ! if $comment or $block; $block -= () = /(\})/g; $comment = 0 unless $block; } print $out $_ unless $comment; }
        i think it may need a loop to loop throw target domain zone and then delete the files from the zone header to the end of zone