awstats中更新httpd.conf文件日志格式的代码

| 暂无评论 | 暂无引用通告

-->

sub update_httpd_config
{
        my $file=shift;
        if (! $file) { error("Call to update_httpd_config with wrong parameter"); }

        open(FILE, $file) || error("Failed to open $file for update");
        open(FILETMP, ">$file.tmp") || error("Failed to open $file.tmp for writing");

        # $%conf contains param and values
        my %confchanged=();
        my $conflinenb = 0;

        # First, change values that are already present in old config file
        while(<FILE>) {
                my $savline=$_;

                chomp $_; s/\r//;
                $conflinenb++;

                # Remove comments not at beginning of line
                $_ =~ s/\s#.*$//;

                # Change line
                if ($_ =~ /^CustomLog\s(.*)\scommon$/i) { $savline="CustomLog $1 combined"; }

                # Write line
                print FILETMP "$savline";
        }

        close(FILE);
        close(FILETMP);

        # Move file to file.sav
        if (rename("$file","$file.old")==0) {
                error("Failed to make backup of current config file to $file.old");
        }

        # Move tmp file into config file
        if (rename("$file.tmp","$file")==0) {
                error("Failed to move tmp config file $file.tmp to $file");
        }

        return 0;
}

其中error子例程是打印退出!

暂无引用通告

发送引用通告网址: http://supersun.info/mt/mt-tb.cgi/703
如果您想引用这篇日记到您的Blog,请复制上面的链接,放置到您发表文章时的相应界面中。

发表评论

最新资源

  • IMG_1437.JPG
  • line.png
  • bar.png
  • perl_calander.jpg

关于此日记

此日记由 supersun 发表于 2007年7月24日 11:30

此Blog上的上一篇日记我喜欢的防火墙ZoneAlarm

此Blog上的下一篇日记我年轻时所不了解的事情

首页归档页可以看到最新的日记和所有日记。