Hello everyone, I have a little issue that I am sure someone has come across here once before and was wondering if I can get some pointers.
I am trying to read and grab values from a "messy" httpd.conf file. What I am trying to do is grab the ServerName value and DocumentRoot value for a given VirtualHost depending on the username I have defined. The httpd.conf file has many VirtualHost sections (50 +). And each section does not have the same order of directives as the next. For example: <VirtualHost domain1.com> ScriptAlias /cgi-bin/ /usr/www/htdocs/lee/domain1-www/cgi-bin/ DocumentRoot /usr/www/htdocs/lee/domain1-www ServerAdmin [EMAIL PROTECTED] ServerName domain1.com User lee </VirtualHost> <VirtualHost domain4.com> User bob DocumentRoot /usr/www/htdocs/bob/domain1-www ServerAdmin [EMAIL PROTECTED] ScriptAlias /cgi-bin/ /usr/www/htdocs/bob/domain1-www/cgi-bin/ ServerName domain4.com </VirtualHost> So I wanted to write a script that if I have a username I could use that to get the ServerName and DocumentRoot from the correct VirtualHost Section. Here is what I have: ----------------------<code>----------------------------------------- #!/usr/local/bin/perl use strict; use warnings; use diagnostics; $|++; use vars qw( $httpd_conf_dir $httpd_conf_file $owner $servername $docroot $user ); $httpd_conf_dir = '/etc/httpd/conf'; $httpd_conf_file = "$httpd_conf_dir/httpd.conf"; $user = 'lee'; $/ = '<V'; open (HTTPD, "$httpd_conf_file") or die "cannot open $httpd_conf_file:$!"; while (<HTTPD>) { if (/irtualHost/) { $owner = $1 if /^User\s*(\d+)/m; next if ($owner ne $user); $servername = $1 if /^ServerName\s*(\w+)/m; $docroot = $1 if /^DocumentRoot\s*(.+)/m; } } close (HTTPD); print "$owner : $servername : $docroot\n"; ------------------</code>------------------------------------------ But this just doesn't work. I get the last VirtualHost sections servername (minus the .com) and the Docroot. But the username isn't there.. Can anyone steer me in the right direction? THanks, Chad -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>