#!/usr/bin/perl $confpath="/etc/httpd/conf"; $bakpath="/etc/httpd/conf/bak"; $commonconf="commonhttpd.conf"; system("mkdir -p $bakpath") ==0 or die "Can't create backup directory $bakpath\n"; sub fixcommon{ while (<CONFF>) { s|^(.*)(PerlHandler Apache::)(.*)|$1<IfDefine !APACHE2>\n$1 $2$3\n$1</IfDefine>\n$1<IfDefine APACHE2>\n$1 PerlResponseHandler ModPerl::$3\n$1</IfDefine>|gi; s|^(.*)(PerlModule)(.*)|$1<IfDefine !APACHE2>\n$1 $2$3\n$1</IfDefine>|gi; print NEW $_; } } $_=`date +%Y%m%d-%T`;chop;s/:/./g;$dat=$_; #Fix commonhttpd.conf `cp -f $confpath/$commonconf $bakpath/$commonconf-$dat`; if (`grep -c APACHE2 $confpath/$commonconf` == 0) { open(CONFF,"$bakpath/$commonconf-$dat") or die "Can't create $bakpath/$commonconf-$dat\n"; open(NEW,">$confpath/$commonconf") or die "Can't open $confpath/$commonconf\n"; fixcommon; close(CONFF); close(NEW); }