gornox_zx has asked for the wisdom of the Perl Monks concerning the following question:
~heise2k~#!/usr/bin/perl -w use strict; # a good idea; it brings into existence three strictures my $rawbuf; my $ipbuf; $rawbuf=`/sbin/ifconfig eth0`; if( $rawbuf =~ /(\d+\.\d+\.\d+\.\d+)/ ) { $ipbuf= $1; } else { print "You have no ip address you dazzle-duck! \n"; } vhost($ipbuf); globalip($ipbuf); #-----------------------Behold the function arena--------------------- +# #This function is the template for the apache vhost configuration file +; listen to it sing sub vhost{ my $vfile = "/etc/httpd/conf/virtualhosts.conf"; open (VHOST, "> $vfile") or die "The virtual hosts configuration file +is virtual all right! $!\n"; my $ipnum = "$_[0]"; my @bigbuf = ( "NameVirtualHost $ipnum\n\n", "<VirtualHost $ipnum>\n", "User hg\n","Group hg\n", "DocumentRoot /www/hg\n", "ServerName 0tis.org\n", "ServerAlias www.0tis.org\n", "ScriptAlias /cgi-bin /www/hg/cgi-bin\n", "</VirtualHost>\n" ); while (@bigbuf){ my $printbuf = shift ( @bigbuf ); print VHOST $printbuf; } } #code for global ip template sub globalip{ my $ipnum = "$_[0]"; my $globalip = "/usr/share/global.ip"; open (GIP,"> $globalip") or die "You silly silly man, why must you ins +ist on opening a non-existant configuration file $!\n"; print GIP "\$ipnum = $ipnum;\n1;"; close (GIP); }
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Updating config files with dynamic ip
by mr.nick (Chaplain) on Jul 27, 2001 at 17:56 UTC | |
(ar0n: <Perl> sections) Re: Updating config files with dynamic ip
by ar0n (Priest) on Jul 27, 2001 at 19:35 UTC |