in reply to Re^4: FEAR OF PERL
in thread FEAR OF PERL

adding a domain in the named file and create the zone file in /var/named
I'm not sure how sophisticated you are in
administrating this stuff *at all* (without Perl).
There is something out there that describes
how to handle complicated things in the zone files,
eg. Format of DNS files.

Adding or modifying something depends IMHO entirely
on the conventions already used on your server (what only you may know).
adding virtual host to apache httpd.conf file
This is the same like above. Normally, you won't "add"
anything to "httpd.conf", but rather let include "httpd.conf"
subdirectories containing configuration files, like this
[httpd.conf] example piece:
...
Include /etc/apache2/vhosts-batch-01/*.conf
Include /etc/apache2/vhosts-batch-02/*.conf
...
In these directories, you may provide specialized
configuration files (xyz123.conf) for any http service you provide.
In each directory you may have some "common.inc" file
which gets included by each .conf in the respective directory

But that's the Black Art of Apache Configuration and
this hasn't very much to do with Perl in the first place.
Once you are able to create a consistent multihost
configuration at all, there should be no problem to
write some Perl-Scripts that may manage them

Regards

mwa

Replies are listed 'Best First'.
Re^6: FEAR OF PERL
by firewall00 (Acolyte) on Oct 14, 2007 at 20:57 UTC
    thanks mwa and thanks for you tips also
    iam now having a problem and i think it's stupidness to have such one
    i posts some posts about how to comment zones in the zone file and i got a wonderful answers and a good code especially from shmem
    by the way here is the code shmem wrote
    #!/usr/bin/perl -w use strict; print " please enter the domain name: "; my $targetdomain = <STDIN>; chomp $targetdomain; my $file = "/home/blackice/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 $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 $_; }

    and it works very well and i understand the way of that script works and it was agood idea
    but i want to add some feature to this script i want to add the date at the top of the zone when that zone was commented on
    i have tried to make some tries ,, i have creates my $date = `date -u "+%m/%d/%Y %H:%M:%S"`; this is a date string that i can print in the script and i tried to print it here
    print "date"; print $out $_;

    also i have tried to print it before this line  print $out '// '.$_; next; but it failed ,, i also have tried to print it in some other places and it also fails
    so can you help me of how to think about that

    thanks

      i finally knows hot to do it :)
      first i would to say perl is great language and all perl people are helpful and iam going to learn , learn and learn GOD willing
      here is the code to make the whole task
      #!/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/blackice/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 $comment = 0; my $block = 0; while(<$in>) { if (/^zone\s+"$targetdomain"/) { print $out '// ' . $char; print $out ': ' . $susdate; $comment++; $block += () = /(\{)/g; print $out '// '.$_; next; } if($comment) { $block += () = /(\{)/g; s!^!// ! if $comment or $block; $block -= () = /(\})/g; $comment = 0 unless $block; } print $out $_; }

      Thanks for all

        Congratulations on modifying this script so that it meets your needs!

        Now take some time to comment the heck out of the script. Hit every line, and explain in plain language what it is you are doing and why.

        Now that you understand what all of the code is doing, is there anything redundant or broken in the code that should be removed or fixed?

        If I were reviewing this code, I would make these suggestions:

        • Add some comments.
        • use warnings.
        • Line 32 has a redundant condition in its if clause.
        • Use Perl's date functions instead of shelling out to `date` in line 9.
        • Use scalars in interpolated strings to simplify formatting of data. (Lines 24,25).

        It's clear that you are making progress. Keep up the good work and you will continue to build your skills.


        TGI says moo