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

i had some problems and i posted all of it here like how to comment line in named.conf file and i felt my self dummy :S
cuz of my frequently asked questions in the same thread
but what i want to do is to managing linux and servers by perl like editing in itis configuration file
like adding a domain in the named file and create the zone file in /var/named
adding virual host to apache httpd.conf file
and various type of linux administration

thanks for your great support

Replies are listed 'Best First'.
Re^5: FEAR OF PERL
by mwah (Hermit) on Oct 14, 2007 at 14:31 UTC
    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
      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