Hi all,

I am relatively new to Perl. Was learning references and thought of creating
a script that will list the username and its list of domains from httpd.conf
(on a cpanel server). I am curious to know why line

if (/DocumentRoot \/home\/(\S+?)\//) {

works whereas

if (#DocumentRoot /home/(\S+?)/#) {

does not, in the below script. Kindly help. Seems I am missing something
simple here.

Regards,
Vimal



====================================
#!/usr/bin/perl

my $test;
my %virtualhost;
my @temp = ();
my $user;

open (FILE, " <httpd.conf") || die "Cannot open: $!";
while (<FILE>){
    chomp;
    $test=1 if /<VirtualHost/ ;
    $test=0 if /^<\/VirtualHost/ ;
    @temp=() if /^<\/VirtualHost/ ;
    if ($test == 1){
        push @temp, $1 if /ServerName (\S+)\s?/ ;
        push @temp, $1 if /ServerAlias (?:(\S+)\s*)+/ ;
        if (/DocumentRoot \/home\/(\S+?)\//) {    # WORK FINE
#        if (#DocumentRoot /home/(\S+?)/#) {    # DOES NOT WORK
          $user = $1;
          $virtualhost{$user} = [] unless exists $virtualhost{$user} ;
          push @{$virtualhost{$user}}, @temp;
          @temp = ();
          $test = 0;
        }
    }
}
close FILE;

print "APACHE REPORT \n\n\n";
foreach (sort keys %virtualhost) {
    print " -> Username:\t$_ \n -> Domains:\t";
    @temp = @{$virtualhost{$_}};
    print "$_\n\t\t" foreach sort @temp;
    print "\n";
}
====================================

Reply via email to