We help IT Professionals succeed at work.

Perl Script to edit httpd.conf and changes few options

xBellox
xBellox asked
on
433 Views
Last Modified: 2012-05-06
Hi,

  I have experience with programming (PHP, javascript, Delphi)... But I'm new on Perl Programming. What I need is one script that opens one file modify some block of text and save it.

   More specifically, I need to edit the apache httpd.conf modify 3 or 4 lines and save it. Here is the before and after:


BEFORE:

~~~~ some block of text ~~~~

<VirtualHost 255.255.255.0>
DocumentRoot /home/./username/documentroot
ServerName www.domainname.com.br
RewriteEngine On
<Directory /home/./username/documentroot>
    AddType application/x-httpd-php .php .php3
    php_admin_flag safe_mode On
    php_admin_value include_path ".:/tmp/:/home/./username/documentroot"
    php_admin_value open_basedir ".:/tmp/:/home/./username/documentroot"
    php_admin_value safe_mode_include_dir /home/./username/documentroot
</Directory>
</VirtualHost>

~~~~ the rest of file ~~~~

AFTER:

~~~~ some block of text ~~~~~~~

<VirtualHost 255.255.255.0>
DocumentRoot /home/./username/documentroot
ServerName www.domainname.com.br
RewriteEngine On
CustomLog /home/./username/logs/access_log combined   <--- new line
<Directory /home/./username/documentroot>
    AddType application/x-httpd-php .php .php3
    php_admin_flag safe_mode On
    php_admin_value include_path ".:/tmp/:/home/./username/documentroot"
    php_admin_value open_basedir ".:/tmp/:/home/./username/documentroot
    php_admin_value safe_mode_include_dir /home/./username/documentroot
</Directory>
<Directory /home/./username/documentroot/stats>    <--- new line
    AllowOverride AuthConfig     <--- new line
</Directory>    <--- new line
</VirtualHost>


~~~~ the rest of file ~~~~


But the is more... Before insert the new lines I must be sure that they doesn't exists already.


Please help, thanks :)

Comment
Watch Question

Top Expert 2009
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION
Top Expert 2009
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Author

Commented:
@mrjoltcola:

   Like I said, I'm new on perl scripting, I need more help than that. Thank you.


-------------------------

@Adam314:

   The script I need it's more complex than add lines at the end of the file. I'm googling "mrjoltcola"...

--------------------------

@ghostdog74

 I need to be in perl cause it will run inside another perl script. Thank you anyway.
Top Expert 2009
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION
Top Expert 2009

Commented:
>>I'm googling "mrjoltcola"

Don't do that, you don't want any of my modules for this! :)

If you aren't comfortable installing the module I mentioned, I would stick with Adam's solution, he will get you what you need.

Author

Commented:
It gave me a clue...
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.